在springboot工程下的pom.xml中添加依赖
<!--分页 pagehelper --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.5</version> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.1.1</version> </dependency>
在工程的配置Application文件中添加如下代码
#pagehelper分页插件配置 pagehelper.helperDialect=mysql pagehelper.reasonable=true pagehelper.supportMethodsArguments=true pagehelper.params=count=countSql
对service层的更改
@Service public class UserService2 { @Autowired private UserDao userDao; public PageInfo<User> queryAll(Integer page, Integer pageSize ){ PageHelper.startPage(page,pageSize);//分页起始码以及每页页数 List<User> users=userDao.selectAll(); PageInfo pageInfo=new PageInfo(users); return pageInfo; }
对controller层的更改
@Controller public class UserController2 { @Autowired private UserService2 userService2; @RequestMapping("queryAll") @ResponseBody public List<User> query(@RequestParam(value="page",defaultValue="1")Integer page, @RequestParam(value="pageSize",defaultValue="2")Integer pageSize){ PageInfo<User> pageInfo=userService2.queryAll(page,pageSize); return pageInfo.getList(); } }
原文地址:https://www.cnblogs.com/sitian2050/p/11827106.html
时间: 2024-10-09 22:07:12