springBoot之PageHelper分页

项目中使用这个工具分页特别好,记录一下。。。

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;
    }


}

这样就实现了分页简单吧。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值