springboot分页插件的使用
在springboot工程下的pom.xml中添加依赖
com.github.pagehelper pagehelper-spring-boot-starter 1.2.5 org.mybatis.spring.boot mybatis-spring-boot-starter 2.1.1在工程的配置Application文件中添加如下代码
#pagehelper分页插件配置pagehelper.helperDialect=mysqlpagehelper.reasonable=truepagehelper.supportMethodsArguments=truepagehelper.params=count=countSql对service层的更改
@Servicepublic class UserService2 { @Autowired private UserDao userDao; public PageInfo queryAll(Integer page, Integer pageSize ){ PageHelper.startPage(page,pageSize);//分页起始码以及每页页数 List users=userDao.selectAll(); PageInfo pageInfo=new PageInfo(users); return pageInfo; }对controller层的更改
@Controllerpublic class UserController2 { @Autowired private UserService2 userService2; @RequestMapping("queryAll") @ResponseBody public List query(@RequestParam(value="page",defaultValue="1")Integer page, @RequestParam(value="pageSize",defaultValue="2")Integer pageSize){ PageInfo pageInfo=userService2.queryAll(page,pageSize); return pageInfo.getList(); }}