返回顶部
首页 > 资讯 > 后端开发 > Python >SpringBoot整合Mybatis-Plus分页失效的解决
  • 510
分享到

SpringBoot整合Mybatis-Plus分页失效的解决

SpringBootMybatis-Plus分页失效SpringBootMybatis-Plus分页 2023-01-09 15:01:31 510人浏览 泡泡鱼

Python 官方文档:入门教程 => 点击学习

摘要

场景:项目整合mybatis-Plus分页失效,current一直是1,size一直是10,total属性一直是0,数据分页不准 先看官网给的示例:  解决方案是新建m

场景:项目整合mybatis-Plus分页失效,current一直是1,size一直是10,total属性一直是0,数据分页不准

先看官网给的示例:

 解决方案是新建mybatis-Plus的配置文件:

package com.amc.config;
 
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
 

@EnableTransactionManagement
@MapperScan("com.amc.**.mapper")
@Configuration
public class MyBatisPlusConfig {
 
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        PaginationInnerInterceptor innerInterceptor = new PaginationInnerInterceptor();
        innerInterceptor.setDbType(DbType.Mysql);
        innerInterceptor.setOverflow(true);
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        interceptor.addInnerInterceptor(innerInterceptor);
        return interceptor;
    }
 
    @Bean
    public ConfigurationCustomizer configurationCustomizer() {
        return mybatisConfiguration -> mybatisConfiguration.setUseGeneratedShorTKEy(false);
    }
}

 响应:

{

    "code": "00",

    "msg": "成功",

    "data": {

        "records": [

            {

                "userId": "1599928568143081472",

                "userName": "admin",

                "nickName": "张三",

                "userType": "00",

                "email": "23*****405@qq.com",

                "phoneNumber": "184****6521",

                "sex": "0",

                "avatar": "Http://xxxx",

                "passWord": "uLRrSaBv+ERnSHOw9Yge9A==",

                "birthday": null,

                "townId": null,

                "townName": "",

                "countyId": null,

                "countyName": "",

                "provinceId": null,

                "provinceName": "",

                "cityName": "",

                "cityId": null,

                "detailAddress": "山东省济南市历下区",

                "status": "0",

                "delFlag": "0",

                "loginIp": "",

                "loginDate": null,

                "createBy": "",

                "createTime": "2022-12-06T00:47:50.000+0000",

                "updateBy": "",

                "updateTime": null,

                "remark": "这是注册用户测试",

                "tenantId": "-1",

                "revision": null

            }

        ],

        "total": 1,

        "size": 1,

        "current": 1,

        "orders": [],

        "optimizeCountsql": true,

        "hitCount": false,

        "countId": null,

        "maxLimit": null,

        "searchCount": true,

        "pages": 1

    }

}

至此,分页方案解决完毕!!!

到此这篇关于SpringBoot整合Mybatis-Plus分页失效的解决的文章就介绍到这了,更多相关SpringBoot Mybatis-Plus分页失效内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

--结束END--

本文标题: SpringBoot整合Mybatis-Plus分页失效的解决

本文链接: https://lsjlt.com/news/177197.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作