首先在springboot项目的maven中加入依赖(版本可能需要自己选择合适的)
<dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.3</version> </dependency>
接着在配置文件中加入配置信息
#pagehelper分页插件配置
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
之后在相关服务层、控制层传入pageNum和pageSize参数就好了
服务层
public interface UserService { List<User> selectAll(int pageNum, int pageSize); int updateUserByAge(); }
@Override public List<User> selectAll(int pageNum, int pageSize) { PageHelper.startPage(pageNum,pageSize); return userMapper.selectAll(); }
控制层
@RequestMapping(value="/all",method = RequestMethod.GET) @ResponseBody public List<User> selectAll(@RequestParam int pageNum,@RequestParam int pageSize){ return userService.selectAll(pageNum,pageSize); }