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;
        }
    }

    结束

  • 相关阅读:
    Android:日常学习笔记(7)———探究UI开发(1)
    Android:日常学习笔记(6)——探究活动(4)
    JavaScript:基础扩展(1)——JSON
    JavaScript:学习笔记(3)——正则表达式的应用
    正则表达式:快速入门
    LeetCode_Easy_471:Number Complement
    Java实现——字符串分割以及复制目录下的所有文件
    DOM、SAX、JDOM、DOM4J以及PULL在XML文件解析中的工作原理以及优缺点对比
    一个简单电商网站开发过程中的业务资料整理
    大道至简,不简则死
  • 原文地址:https://www.cnblogs.com/it-deepinmind/p/12794396.html
Copyright © 2011-2022 走看看