做企业网站需要建多大的画布网站制作周期
做企业网站需要建多大的画布,网站制作周期,企业营销策划是什么意思,seo佛山目录 一、前置工作: 1.整体项目目录结构 2.创建普通javamaven项目。 3.导入依赖#xff0c;改造成springboot项目 4.配置启动类 5.创建service接口及其实现类 6.创建接口Mapper 7.配置数据源 8.创建数据库表
二、使用MP#xff08;mybatisplus#xff09;的分页插件
二、使…目录 一、前置工作: 1.整体项目目录结构 2.创建普通javamaven项目。 3.导入依赖改造成springboot项目 4.配置启动类 5.创建service接口及其实现类 6.创建接口Mapper 7.配置数据源 8.创建数据库表
二、使用MPmybatisplus的分页插件
二、使用自定义的分页插件 MyBatis Plus自带分页插件只要简单的配置即可实现分页功能。 一、前置工作: 1.整体项目目录结构 2.创建普通javamaven项目。 3.导入依赖改造成springboot项目 依赖
?xml version1.0 encodingUTF-8?
project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdcom.qcby/groupIdartifactIdSpringBootMybatisPlus/artifactIdversion1.0-SNAPSHOT/versionparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.4.0/versionrelativePath/ !-- lookup parent from repository --/parentdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependencydependencygroupIdcom.baomidou/groupIdartifactIdmybatis-plus-boot-starter/artifactIdversion3.5.1/version/dependencydependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdoptionaltrue/optional/dependencydependencygroupIdmysql/groupIdartifactIdmysql-connector-java/artifactIdversion5.1.46/versionscoperuntime/scope/dependency/dependenciesbuildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactId/plugin/plugins/build/project 4.配置启动类
package com.qcby;import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;SpringBootApplication
MapperScan(com.qcby.SpringBoot.mapper)
public class SpringBootApplication1 {public static void main(String[] args) {SpringApplication.run(SpringBootApplication1.class, args);}
}5.配置实体类
package com.qcby.SpringBoot.pojo;import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;Data
TableName(t_product)
public class Product {private Long id;private String name;private Integer price;private Integer version;
}package com.qcby.SpringBoot.pojo;import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;Data //set和get方法
AllArgsConstructor //全参构造器
NoArgsConstructor //无参构造器
TableName(t_user)
public class User {//因为用到雪花算法所以用Long属性TableIdprivate Long id;private String name;private Integer age;private String email;TableLogicprivate Integer isDeleted;
}5.创建service接口及其实现类
package com.qcby.SpringBoot.service;import com.baomidou.mybatisplus.extension.service.IService;
import com.qcby.SpringBoot.pojo.User;/*** UserService继承IService模板提供的基础功能*/
public interface UserService extends IServiceUser {
}package com.qcby.SpringBoot.service.Impl;import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qcby.SpringBoot.mapper.UserMapper;
import com.qcby.SpringBoot.pojo.User;
import com.qcby.SpringBoot.service.UserService;
import org.springframework.stereotype.Service;/*** ServiceImpl实现了IService提供了IService中基础功能的实现* 若ServiceImpl无法满足业务需求则可以使用自定的UserService定义方法并在实现类中实现*/
Service
public class UserServiceImpl extends ServiceImplUserMapper, User implements UserService {}6.创建接口Mapper
package com.qcby.SpringBoot.mapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qcby.SpringBoot.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;Mapper
public interface UserMapper extends BaseMapperUser {}package com.qcby.SpringBoot.mapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qcby.SpringBoot.pojo.Product;
import org.apache.ibatis.annotations.Mapper;Mapper
public interface ProductMapper extends BaseMapperProduct {
}7.配置数据源 在application.yaml中配置信息。
spring:# 配置数据源信息datasource:# 配置数据源类型type: com.zaxxer.hikari.HikariDataSource# 配置连接数据库信息driver-class-name: com.mysql.jdbc.Driverurl: jdbc:mysql://localhost:3306/mybatis_plus?characterEncodingutf-8useSSLfalseusername: rootpassword: root
# 配置MyBatis日志
mybatis-plus:configuration:log-impl: org.apache.ibatis.logging.stdout.StdOutImpl 8.创建数据库表 二、使用MPmybatisplus的分页插件 首先要在容器中配置一个mybatisplus分页插件的bean。 可以自定义一个配置类也可以在启动类中配置因为启动类也是一个配置类。
package com.qcby.SpringBoot.config;import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;Configuration
public class MybatisPlusConfig {/*** 分页插件* 构建一个拦截来处理分页* 每个数据库厂商对于分页的实现语法有差别因此在声明该拦截时需要指定应用的数据库类型* return*/Beanpublic MybatisPlusInterceptor mybatisPlusInterceptor() {MybatisPlusInterceptor interceptor new MybatisPlusInterceptor();interceptor.addInnerInterceptor(newPaginationInnerInterceptor(DbType.MYSQL));//由于各个数据库的语法会有差别因此要指明数据库类型return interceptor;}
}编写测试类
package com.qcby;import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qcby.SpringBoot.mapper.ProductMapper;
import com.qcby.SpringBoot.mapper.UserMapper;
import com.qcby.SpringBoot.pojo.Product;
import com.qcby.SpringBoot.pojo.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.util.List;SpringBootTest
public class Test2 {Autowiredprivate UserMapper userMapper;Autowiredprivate ProductMapper productMapper;Testpublic void testPage(){//设置分页参数PageUser page new Page(1, 5);userMapper.selectPage(page, null);//获取分页数据ListUser list page.getRecords();list.forEach(System.out::println);System.out.println(当前页page.getCurrent());System.out.println(每页显示的条数page.getSize());System.out.println(总记录数page.getTotal());System.out.println(总页数page.getPages());System.out.println(是否有上一页page.hasPrevious());System.out.println(是否有下一页page.hasNext());}}二、使用自定义的分页插件 在usermapper中加入方法
package com.qcby.SpringBoot.mapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qcby.SpringBoot.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;Mapper
public interface UserMapper extends BaseMapperUser {/*** 根据年龄查询用户列表分页显示* param page 分页对象 ,xml中可以从里面进行取值 ,传递参数 Page 即自动分页 ,必须放在第一位* param age 年龄* return*//*** 不用加limit语句因为配置了一个拦截的插件只需要传入page对象还是使用的MP的分页插件* param page* param age* return*/Select(SELECT id,name,age,email FROM t_user WHERE age #{age})IPageUser selectPageVo(Param(page) PageUser page, Param(age) Integer age);
}package com.qcby;import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qcby.SpringBoot.mapper.ProductMapper;
import com.qcby.SpringBoot.mapper.UserMapper;
import com.qcby.SpringBoot.pojo.Product;
import com.qcby.SpringBoot.pojo.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.util.List;SpringBootTest
public class Test2 {Autowiredprivate UserMapper userMapper;Autowiredprivate ProductMapper productMapper;Testpublic void testSelectPageVo(){//设置分页参数PageUser page new Page(1, 5);userMapper.selectPageVo(page, 20);//获取分页数据ListUser list page.getRecords();list.forEach(System.out::println);System.out.println(当前页page.getCurrent());System.out.println(每页显示的条数page.getSize());System.out.println(总记录数page.getTotal());System.out.println(总页数page.getPages());System.out.println(是否有上一页page.hasPrevious());System.out.println(是否有下一页page.hasNext());}
}
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/87741.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!