El uso del complemento de paginación MybatisPlus

El uso del complemento de paginación MybatisPlus

Realice la visualización de la lista de hospitales

1. Agregar interfaz de paginación de servicios e implementación

Agregar interfaz de paginación a la clase HospitalService

/**
 * 分页查询
 * @param page 当前页码
 * @param limit 每页记录数
 * @param hospitalQueryVo 查询条件
 * @return
*/
Page<Hospital> selectPage(Integer page, Integer limit, HospitalQueryVo hospitalQueryVo);

La clase HospitalServiceImpl implementa paginación

@Override
public Page<Hospital> selectPage(Integer page, Integer limit, HospitalQueryVo hospitalQueryVo) {
    
    
      Sort sort = Sort.by(Sort.Direction.DESC, "createTime");
//0为第一页
Pageable pageable = PageRequest.of(page-1, limit, sort);

      Hospital hospital = new Hospital();
      BeanUtils.copyProperties(hospitalQueryVo, hospital);

//创建匹配器,即如何使用查询条件
ExampleMatcher matcher = ExampleMatcher.matching() //构建对象
.withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING) //改变默认字符串匹配方式:模糊查询
.withIgnoreCase(true); //改变默认大小写忽略方式:忽略大小写

      //创建实例
Example<Hospital> example = Example.of(hospital, matcher);
      Page<Hospital> pages = hospitalRepository.findAll(example, pageable);

return pages;
   }

2. Agregar método de controlador

Agregue la clase com.atguigu.yygh.hosp.controller.HospitalController

package com.atguigu.yygh.hosp.controller;

@Api(tags = "医院管理接口")
@RestController
@RequestMapping("/admin/hosp/hospital")
public class HospitalController {
    
    

@Autowired
private HospitalService hospitalService;

@ApiOperation(value = "获取分页列表")
@GetMapping("{page}/{limit}")
public Result index(
@ApiParam(name = "page", value = "当前页码", required = true)
@PathVariable Integer page,

@ApiParam(name = "limit", value = "每页记录数", required = true)
@PathVariable Integer limit,

@ApiParam(name = "hospitalQueryVo", value = "查询对象", required = false)
                HospitalQueryVo hospitalQueryVo) {
    
    
return Result.ok(hospitalService.selectPage(page, limit, hospitalQueryVo));
   }

}

Supongo que te gusta

Origin blog.csdn.net/david2000999/article/details/122503972
Recomendado
Clasificación