当前位置:网站首页>Lecturer paging query_ Instructor condition query with page

Lecturer paging query_ Instructor condition query with page

2022-06-11 03:21:00 The bright moon is always fresh

Lecturer paging query

1、 Add the plug-in 
/** *  Paging plug-ins  */
@Bean
public PaginationInterceptor paginationInterceptor() {
    
    return new PaginationInterceptor();
}
2、 Implementation method 
@ApiOperation(value = " Query the instructor list in pages ")
    @GetMapping("getTeacherPage/{current}/{limit}")
    public R getTeacherPage(@PathVariable Long current,
                            @PathVariable Long limit){
    
        Page<EduTeacher> page = new Page<>(current,limit);
        teacherService.page(page,null);
        List<EduTeacher> records = page.getRecords();
        long total = page.getTotal();
        //1、 Deposit in MAP
// Map<String,Object> map = new HashMap<>();
// map.put("list",records);
// map.put("total",total);
// return R.ok().data(map);
        //2、 Directly joining together 
        return R.ok().data("list",records).data("total",total);

    }

3、 test 

Instructor condition query with paging

1、 Demand analysis

 Insert picture description here

2、 Implementation interface

(1) establish VO object


@Data
public class TeacherQuery  implements Serializable {
    

    @ApiModelProperty(value = " Teacher's name , Fuzzy query ")
    private String name;

    @ApiModelProperty(value = " title  1 Senior lecturer  2 Chief lecturer ")
    private Integer level;

    @ApiModelProperty(value = " Query start time ", example = "2019-01-01 10:10:10")
    private String begin;// Be careful , What we use here is String type , The data transmitted from the front end does not need type conversion 

    @ApiModelProperty(value = " Query end time ", example = "2019-12-01 10:10:10")
    private String end;
}

(2) Implementation method


@ApiOperation(value = " Query the instructor list by page with conditions ")
    @PostMapping("getTeacherPageVo/{current}/{limit}")
    public R getTeacherPageVo(@PathVariable Long current,
                              @PathVariable Long limit,
                              @RequestBody TeacherQuery teacherQuery){
    
        //@RequestBody hold json String into entity class 
        //1、 Get the query criteria 
        String name = teacherQuery.getName();
        Integer level = teacherQuery.getLevel();
        String begin = teacherQuery.getBegin();
        String end = teacherQuery.getEnd();
        //2、 Judge whether the condition is empty , If it is not empty, spell it sql
        QueryWrapper<EduTeacher> wrapper = new QueryWrapper<>();
        if(!StringUtils.isEmpty(name)){
    
            wrapper.like("name",name);
        }
        if(!StringUtils.isEmpty(level)){
    
            wrapper.eq("level",level);
        }
        if(!StringUtils.isEmpty(begin)){
    
            wrapper.ge("gmt_create",begin);
        }
        if(!StringUtils.isEmpty(end)){
    
            wrapper.le("gmt_create",end);
        }
        
        Page<EduTeacher> page = new Page<>(current,limit);
        teacherService.page(page,wrapper);
        List<EduTeacher> records = page.getRecords();
        long total = page.getTotal();
        //1、 Deposit in MAP
// Map<String,Object> map = new HashMap<>();
// map.put("list",records);
// map.put("total",total);
// return R.ok().data(map);
        //2、 Directly joining together 
        return R.ok().data("list",records).data("total",total);

    }

原网站

版权声明
本文为[The bright moon is always fresh]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020554362764.html