MyBatis-Plus dynamic paging query

 1. Front-end request, upload the current page, the size of each page, and the dynamic condition object;

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)
        });
      },

 Request URL

Request URL: http://localhost:8080/admin/doctorcondition?currentPage=1&pagesize=10

Requested data 

 

 2. The interface constructs QuerWrapper based on dynamic conditions, and uses selectPage for paging query;

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);

 According to the conditions, the total page number count(1) is queried, and the page number and the size of each page are added. The query returns the object.

 

3. The returned json

Guess you like

Origin blog.csdn.net/qq_29752857/article/details/113589656