欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Springboot mybatisplus如何解決分頁組件IPage失效問題

 更新時(shí)間:2024年08月01日 08:54:29   作者:草青工作室  
這篇文章主要介紹了Springboot mybatisplus如何解決分頁組件IPage失效問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

Springboot-mybatisplus-解決分頁組件IPage失效問題

背景

mybatisplus的分頁插件IPage很好用,不管是基于@select注解還是基于XML的都可以實(shí)現(xiàn)分頁查詢;

不知道代碼有什么改動(dòng),用著用著就分頁居然不好使了-_-,select時(shí)由于沒有注入分頁條件,導(dǎo)致將所有結(jié)果都返回了。

沒有深究直接上解決方案吧!

添加分頁攔截器

@Configuration
public class MybatisPlusConfig {
    @Bean
    public PaginationInterceptor paginationInterceptor(){
        PaginationInterceptor page = new PaginationInterceptor();
        page.setDbType(DbType.POSTGRE_SQL);//選擇對(duì)應(yīng)DB類型
        return page;
    }
}

IPage分頁使用

  • mapper需要繼承BaseMapper
@Repository
public interface XxxMapper extends BaseMapper<XxxMapper > {
    Page<XxxBo> selectAllByPage(IPage<XxxBo> page,@Param("keyword") String keyword);
}
  • XML配置
  <select id="selectAllByPage" resultMap="BaseResultMap">
    select * from xx.xxx where  enable=1
    <if test="keyword != null">
      and (id ~* #{keyword} or name  ~* #{keyword} or  code ~* #{keyword})
    </if>
  </select>
  • 服務(wù)層調(diào)用
    @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;
    }

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論