1.前端请求,传当前页,每页大小,动态条件对象;
userSelect() { this.postRequest("/admin/doctorcondition?currentPage="+ this.currentPage + "&pagesize=" + this.pagesize, this.doctor).then(res => { this.doctorlist = [] if (res.errorCode == -1) { var data = res.body.result.records for (let i = 0; i < data.length; i++) { this.doctorlist.push(data[i]) } this.total = res.body.result.total; } console.log(res.body.result) }); },
请求URL
Request URL: http://localhost:8080/admin/doctorcondition?currentPage=1&pagesize=10
请求写的数据
2.接口根据动态条件构建QuerWrapper,使用selectPage进行分页查询;
Page<Doctor> objectpage=new Page<>(currentPage,pagesize); QueryWrapper<Doctor> qw=new QueryWrapper<>(); if(!"".equals(doctor.getRole())&&doctor.getRole()!=null){ qw.eq("role",doctor.getRole()); } if(!"".equals(doctor.getTrueName())&&doctor.getTrueName()!=null){ qw.like("true_name",doctor.getTrueName()); } if(!"".equals(doctor.getHospital())&&doctor.getHospital()!=null){ qw.like("hospital",doctor.getHospital()); } if(!"".equals(doctor.getCellphone())&&doctor.getCellphone()!=null){ qw.like("cellphone",doctor.getCellphone()); } if(!"".equals(doctor.getEmail())&&doctor.getEmail()!=null){ qw.like("email",doctor.getEmail()); } Page<Doctor> doctors = doctorMapper.selectPage(objectpage, qw);
根据条件查询了总页码count(1),更具页码和每页大小,查询返回对象。
3.返回的json