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(); } }
//分页查询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); }
原文:https://www.cnblogs.com/rightNow666/p/14592189.html