zoukankan      html  css  js  c++  java
  • Mybatis-plus分页不生效解决

    分页代码

        @Override
        public IPage queryStudentList(StudentQueryVI studentQueryVI) {
            if(StringUtil.isNull(studentQueryVI.getUserId())){
                return null;
            }
            Page<StudentVO> page = new Page();
            Integer current = studentQueryVI.getCurrent();
            Integer size = studentQueryVI.getSize();
            if(current == null || current <= 0){
                current = 1;
            }
            page.setCurrent(current);
            if(size != null){
                if(size <= 0 || size > 20){
                    size = 5;
                }
            }else{
                size = 5;
            }
            page.setSize(size);
            List<StudentVO> studentVOList = studentMapper.selectStudentListBySelective(page, studentQueryVI);
            return page.setRecords(studentVOList);
        }
    public interface StudentMapper extends BaseMapper<Student> {
    
        @Select({
                "select user_id, user_name, age, address " +
                "from student" +
                "where user_id = #{userQueryVI.userId} " +
                "order by create_time desc"
        })
        List<StudentVO> selectStudentListBySelective(Page<StudentVO> page, @Param("studentQueryVI") StudentQueryVI studentQueryVI);
    
    }

    解决:

    检查是不是没有加分页插件

    package com.company.base.common.config;
    
    import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
    import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
    import org.mybatis.spring.annotation.MapperScan;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.transaction.annotation.EnableTransactionManagement;
    
    import java.util.Properties;
    
    
    @EnableTransactionManagement
    @Configuration
    @MapperScan({"com.company.pay.repository.mysql.mapper", "com.company.account.repository.mysql.mapper"})
    public class MybatisPlusConfig {
    
        /**
         * 分页插件
         */
        @Bean
        public PaginationInterceptor paginationInterceptor() {
            return new PaginationInterceptor();
        }
    
        /**
         * 打印 sql
         */
        @Bean
        public PerformanceInterceptor performanceInterceptor() {
            PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
            //格式化sql语句
            Properties properties = new Properties();
            properties.setProperty("format", "true");
            performanceInterceptor.setProperties(properties);
            return performanceInterceptor;
        }
    }

    结束

  • 相关阅读:
    另类多线程生产者与消费者模式
    redis.conf配置详细翻译解析
    数据库优化之索引使用简介
    Comparable和Comparator的区别
    spring中用到哪些设计模式
    JVM之几种垃圾收集器简单介绍
    angular.extend()和 angular.copy()的区别
    ThreadLocal是什么?保证线程安全
    excel文件怎么使用php进行处理
    ubuntu 安装ssh 服务
  • 原文地址:https://www.cnblogs.com/it-deepinmind/p/12794396.html
Copyright © 2011-2022 走看看