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

 

結束

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM