MyBatisPlus分页及相关错误

MyBatisPlus分页及相关错误

遇相关报错则持续更新

基本使用

导入mybatisPlus整合springboot相关依赖

		<dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.4.2</version>
        </dependency>

配置mybatis分页配置类

@Configuration
public class MybatisPlusConfig {

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }

}

services中基本使用

@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements IEmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public RespPageBean getEmployeeByPage(Integer currentPage, Integer size, Employee employee, LocalDate[] beginDateScope) {
        //开启分页
        Page<Employee> page = new Page<>(currentPage,size);
        IPage<Employee> employeeByPage = employeeMapper.getEmployeeByPage(page, employee, beginDateScope);
        System.out.println(employeeByPage.getTotal());
        RespPageBean respPageBean = new RespPageBean(employeeByPage.getTotal(),employeeByPage.getRecords());
        return respPageBean;
    }
}

分析:
mybatis分页配置类的代码为新版本的代码,旧版本的代码在此不提供,有兴趣请移步mybatisplus官网https://mp.baomidou.com/guide/page.html,配置中设置数据库为Mysql类型,如您使用的是其他数据库可进行切换配置。
关于分页代码的使用,预先定义一个Page类,传入当前页码和每页尺寸即可,在使用中只需将其放入mapper查询方法中,注意参数位置为第一个,数据返回信息有总条数,每页数据,每页尺寸和当前页码。

相关细节及报错

1.getTotal()方法打印不出数据

在数据输出时,getRecords()可以打印出查询的所有数据,但是每页的总条数始终都是0,遇到此种情况,我的是因为配置类中添加了@Configuration注解却忘记添加@Bean注解,低级错误,各位共勉

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值