Springboot mybatisplus如何解决分页组件IPage失效问题
目录
- Springboot-myBATisplus-解决分页组件IPage失效问题
- 背景
- 添加分页拦截器
- IPage分页使用
- 总结
Springboot-mybatisplus-解决分页组件IPage失效问python题
背景
mybatisplus的分页插件IPage很好用,不管是基于@select注解还是基于XML的都可以实现分页查询;
不知道代码有什么改动,用着用着就分页居然不好使了-_-,select时由于没有注入分页条件,导致将所有结果都返回了。
没有深究直接上解决方案吧!
添加分页拦截器
@Configuration
public class MybatisPlusConfig {
@Bean
public PaginationInterceptor paginationInterceptor(){
PaginationInterceptor page = new PaginationInterceptor();
page.setDbType(DbType.POSTGRE_SQL);//选择对应DB类型
return page;
}
}
IPage分页使用
- mapper需要继承BaseMapper
@Repository
public interface XxxMapper extends BaseMapper<XxxMapper > {
Page<XxxBo> selectAllBphpyPage(IPage<XxxBo> page,@Param("keyword") String keyword);
}
- XML配置
<select id="selectAllByPapythonge" resultMap="BaseResultMap">
select * from xx.xxx where enable=1
<if test="keyword != njsull">
and (id ~* #{keyword} or name ~* #{keyword} or code ~* #{keyword})
</if>
</select>
- 服务层调用
@Override
public Page<XxxBo> viewInfoPage(PageReq req) {
IPage<XxxBo> page = new Page<>(req.getPage().getPage(),req.getPage().getSize());
Page<XxxBo> list = xxxMapper.selectAllByPage(page,req.getKeyword());
return list;
编程 }
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程客栈(www.devze.com)。
加载中,请稍侯......
精彩评论