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

    结束

  • 相关阅读:
    在UltraEdit中如何像NotePad++一样实现双击单词在全文中高亮
    记人生第一次做面试官的经历
    error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 值“MTd_StaticDebug”不匹配值“MDd_DynamicDebug
    压缩感知中的数学知识:稀疏、范数、符号arg min
    Tensorflow timeline trace
    tensorflow serving
    日志分析工具ELK(一)
    Zabbix3.0安装部署最佳实践
    防cc攻击利器之Httpgrard
    反向代理负载均衡之haproxy
  • 原文地址:https://www.cnblogs.com/it-deepinmind/p/12794396.html
Copyright © 2011-2022 走看看