首页 > 其他 > 详细

mybatis-plus分页插件配置

时间:2021-03-29 15:38:43      阅读:354      评论:0      收藏:0      [点我收藏+]

1.创建一个配置类

package com.atguigu.eduservice.config;

import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@MapperScan("com.atguigu.eduservice.mapper")
public class EduConfig {
    /**
     * 逻辑删除插件
     */
    @Bean
    public ISqlInjector sqlInjector() {
        return new LogicSqlInjector();
    }

    /**
     * 分页插件
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }
}

2、分页Controller方法

TeacherAdminController中添加分页方法
//分页查询teacher
    @ApiOperation(value = "分页查询讲师")
    @GetMapping("pageTeacher/{page}/{limit}")
    public R pageListTeacher(@PathVariable long page, @PathVariable long limit) {
        //创建page对象
        Page<EduTeacher> teacherPage = new Page<>(page,limit);
        //调用方法实现分页
        //调用方法时,底层封装,把分页所有数据封装到teacherPage
        IPage<EduTeacher> pageTeacher = eduTeacherService.page(teacherPage, null);
        long total = pageTeacher.getTotal();
        List<EduTeacher> records = pageTeacher.getRecords();

        Map map = new HashMap();
        map.put("total",total);
        map.put("rows",records);

        return R.ok().data(map);
    }

  

  

mybatis-plus分页插件配置

原文:https://www.cnblogs.com/rightNow666/p/14592189.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!