Springboot-mybatisplus-解决分页组件IPage失效问题
Springboot-mybatisplus-解决分页组件IPage失效问题
背景
mybatisplus的分页插件IPage很好用,不管是基于@select注解还是基于XML的都可以实现分页查询;
不知道代码有什么改动,用着用着就分页居然不好使了-_-,select时由于没有注入分页条件,导致将所有结果都返回了。没有深究直接上解决方案吧!
添加分页拦截器
@Configuration
public class MybatisPlusConfig {@Beanpublic PaginationInterceptor paginationInterceptor(){PaginationInterceptor page = new PaginationInterceptor();page.setDbType(DbType.POSTGRE_SQL);//选择对应DB类型return page;}
}
IPage分页使用
mapper需要继承BaseMapper
@Repository
public interface XxxMapper extends BaseMapper {Page selectAllByPage(IPage page,@Param("keyword") String keyword);
}
XML配置
服务层调用
@Overridepublic Page viewInfoPage(PageReq req) {IPage page = new Page<>(req.getPage().getPage(),req.getPage().getSize());Page list = xxxMapper.selectAllByPage(page,req.getKeyword());return list;}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
