网站图片设置软件,网站站群建设进度,wordpress主题yeti1.9.2,wordpress php 模板修改问题概述
SpringBoot中使用mybatis-plus实现分页查询时#xff0c;提供一个page分页对象和一个QueryWrapper条件类对象#xff0c;在使用Service.page(page,queryWrapper)方法进行分页查询时#xff0c;发现并未查询到分页的结果#xff0c;反而是查询到全部符合条件的结果…问题概述
SpringBoot中使用mybatis-plus实现分页查询时提供一个page分页对象和一个QueryWrapper条件类对象在使用Service.page(page,queryWrapper)方法进行分页查询时发现并未查询到分页的结果反而是查询到全部符合条件的结果。
public ListUser getOrdinaryUser() {//创建page分页对象Page pagenew Page(1,3);//查询身份代码为1的普通用户QueryWrapper queryWrappernew QueryWrapper().eq(identity,1);IPage page1 this.page(page, queryWrapper);System.out.println(查询的结果page1.getRecords());return page1.getRecords();}发现其sql语句也是未添加limit
解决方法
在Springboot中若是要使用mybatis-plus实现查询分页首先需要配置一个分页配置类即可配置之后即可实现分页查询。
Configuration
public class MybatisPlusConfig {Beanpublic MybatisPlusInterceptor mybatisPlusInterceptor() {MybatisPlusInterceptor interceptor new MybatisPlusInterceptor();interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));//如果配置多个插件,切记分页最后添加//interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); 如果有多数据源可以不配具体类型 否则都建议配上具体的DbTypereturn interceptor;}
}若还未分页成功则可以原因之一是数据库中没有数据也会导致sql语句中不出现limit为此在实现分页查询的功能时切要添加测试数据到数据库中。 这就是springboot使用mybatis-plus进行分页查询失败的原因之一。