项目中使用这个工具分页特别好,记录一下。。。
1.pom.xml中引入依赖
maven查询网址: https://mvnrepository.com/
<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper-spring-boot-starter -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.12</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.11</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper-spring-boot-autoconfigure -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-autoconfigure</artifactId>
<version>1.2.13</version>
</dependency>
2.application.yml添加
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
3.代码中加入:
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserDao userDao;
@Override
public PageInfo<User> getAllUsers(int pageNum,int pageSize) {
PageHelper.startPage(pageNum,pageSize);
// 不许要修改常规的SQL查询,也不需要使用MySQL的limit或者oracle的ronum分页
List<User> allUsers = userDao.getAllUsers();
PageInfo<User> pageInfo=new PageInfo<>(allUsers);
return pageInfo;
}
@Override
public User getUserById(Integer id) {
User user = userDao.getUserById(id);
System.out.println("------------------这里打印了吗?------------------------------");
System.out.println(JSON.toJSONString(user));
return user;
}
}
这样就实现了分页简单吧。