@Configuration
public class MyBatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor(){
MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
return mybatisPlusInterceptor;
}
}
2.Controller层中创建分页对象,编写分页条件
@GetMapping("/page")
public R<Page> page(int page,int pageSize,String name){
log.info("page={}, pageSize={}, name={}",page,pageSize,name);
//构造分页构造器
Page page1 = new Page(page, pageSize);
//构造条件构造器
LambdaQueryWrapper<Employee> lqw = new LambdaQueryWrapper<>();
//分页条件
lqw.like(StringUtils.isNotEmpty(name),Employee::getName,name);
//添加排序
lqw.orderByDesc(Employee::getUpdateTime);
//执行查询
employeeService.page(page1,lqw);
//返回分页页面信息
return R.success(page1);
}
返回的分页信息响应结果(response)如下:
推荐一个json格式转换神器:JSON转换神器
{"code":1,"msg":null,"data":{"records":[{"id":"157690