一、分页
1、MyBatisPlusConfig中配置分页插件
/*
分页插件
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
2、分页Controller方法
TeacherAdminController中添加分页方法
@ApiOperation(value = “分页讲师列表”)
@GetMapping(“{page}/{limit}”)
public R pageList(
@ApiParam(name = “page”, value = “当前页码”, required = true)
@PathVariable Long page,
@ApiParam(name = “limit”, value = “每页记录数”, required = true)
@PathVariable Long limit){
Page
teacherService.page(pageParam, null);
List
long total = pageParam.getTotal();
return R.ok().data(“total”, total).data(“rows”, records);
}
3、Swagger中测试
二、条件查询
根据讲师名称name,讲师头衔level、讲师入驻时间gmt_create(时间段)查询
1、创建查询对象
创建com.guli.edu.query包,创建TeacherQuery.java查询对象
package com.guli.edu.query;
@ApiModel(value = “Teacher查询对象”, description = “讲师查询对象封装”)
@Data
public class TeacherQuery implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = “教师名称,模糊查询”)
private String name;
@ApiModelProperty(value = “头衔 1高级讲师 2首席讲师”)
private Integer level;
@ApiModelProperty(value = “查询开始时间”, example = “2019-01-01 10:10:10”)
private String begin;//注意,这里使用的是String类型,前端传过来的数据无需进行类型转换
@ApiModelProperty(value = “查询结束时间”, example = “2019-12-01 10:10:10”)
private String end;
}
2、service
接口
package com.guli.edu.service;
public interface TeacherService extends IService
void pageQuery(Page
}
实现
package com.guli.edu.service.impl;
@Service
public class TeacherServiceImpl extends ServiceImpl
@Override
public void pageQuery(Page
QueryWrapper
queryWrapper.orderByAsc(“sort”);
if (teacherQuery == null){
baseMapper.selectPage(pageParam, queryWrapper);
return;
}
String name = teacherQuery.getName();
Integer level = teacherQuery.getLevel();
String begin = teacherQuery.getBegin();
String end = teacherQuery.getEnd();
if (!StringUtils.isEmpty(name)) {
queryWrapper.like(“name”, name);
}
if (!StringUtils.isEmpty(level) ) {
queryWrapper.eq(“level”, level);
}
if (!StringUtils.isEmpty(begin)) {
queryWrapper.ge(“gmt_create”, begin);
}
if (!StringUtils.isEmpty(end)) {
queryWrapper.le(“gmt_create”, end);
}
baseMapper.selectPage(pageParam, queryWrapper);
}
}
3、controller
TeacherAdminController中修改 pageList方法:
增加参数TeacherQuery teacherQuery,非必选
@ApiOperation(value = “分页讲师列表”)
@GetMapping(“{page}/{limit}”)
public R pageQuery(
@ApiParam(name = “page”, value = “当前页码”, required = true)
@PathVariable Long page,
@ApiParam(name = “limit”, value = “每页记录数”, required = true)
@PathVariable Long limit,
@ApiParam(name = “teacherQuery”, value = “查询对象”, required = false)
TeacherQuery teacherQuery){
Page
teacherService.pageQuery(pageParam, teacherQuery);
List
long total = pageParam.getTotal();
return R.ok().data(“total”, total).data(“rows”, records);
}