Mybatis plus 分頁(yè)

基本使用

將分頁(yè)插件注入到bean中

@Configuration
public class MPConfig {
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }
}

使用BaseMapper中提供的分頁(yè)方法

LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.gt(User::getAge, 30);
        Page<User> page = new Page<>(1, 2);
        IPage<User> users = userMapper.selectPage(page, lambdaQueryWrapper);

        System.out.println(users.getTotal());
        System.out.println(users.getRecords());

自定義分頁(yè)

實(shí)際開(kāi)發(fā)中有的分頁(yè)查詢是多表聯(lián)查的,可以通過(guò)自定義SQL查詢的方式

  • 注入分頁(yè)插件
@Configuration
public class MPConfig {
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }
}
  • 定義mapper接口
IPage<User> selectPageUser(Page<User> page, @Param(Constants.WRAPPER)Wrapper<User> wrapper);
  • 定義XML文件
<select id="selectPageUser" resultType="com.naruto.mamba.entity.User">
        select * from user ${ew.customSqlSegment}
</select>
  • 使用分頁(yè)
LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.gt(User::getAge, 30);
        Page<User> page = new Page<>(1, 2);
        IPage<User> users = userMapper.selectPageUser(page, lambdaQueryWrapper);
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 前言: 關(guān)于mybatis-plus的簡(jiǎn)介以及基本使用,我在《mybatis-plus的使用 ------ 入門(mén)》...
    貪挽懶月閱讀 162,423評(píng)論 58 178
  • 1. 簡(jiǎn)介 1.1 什么是 MyBatis ? MyBatis 是支持定制化 SQL、存儲(chǔ)過(guò)程以及高級(jí)映射的優(yōu)秀的...
    笨鳥(niǎo)慢飛閱讀 6,282評(píng)論 0 4
  • (此代碼拷貝可用) 前端與后端分頁(yè)往往存在著數(shù)據(jù) 參數(shù)不對(duì)等的問(wèn)題 例如 當(dāng)前頁(yè) 、每頁(yè)的容量等等 使用插件做...
    天邊的魚(yú)閱讀 2,764評(píng)論 1 0
  • 使用mybatis-plus實(shí)現(xiàn)分頁(yè)查詢 pom.xml導(dǎo)入mybatis-plus插件 編寫(xiě)config 實(shí)現(xiàn)分...
    你所熱愛(ài)的閱讀 4,569評(píng)論 0 2
  • 昨晚,睡在我身邊的兒子,好幾次迷迷糊糊睜開(kāi)眼,定位好我的位置,就搖搖晃晃地朝我爬過(guò)來(lái),一邊邊倚著我躺下,一邊含糊地...
    Anita的奇妙花園閱讀 450評(píng)論 0 10

友情鏈接更多精彩內(nèi)容