mybatis-plus分页查询

如果只是单表,那么分页查询就容易的多了
这里的@ModelAttribute注解可以将前端传过来的currentsize字段映射到Page对象中
BaseController中

    /**
     * @param page 查询一般传入参数为current和size, 例如/listPage?current=1&size=5,
     * @return 返回分页数据
     */
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    public ResponseObj> listPage(@ModelAttribute Page page, @ModelAttribute T model) {
        Page pageList = service.selectPage(page, new EntityWrapper<>(model));
        for (T eachObj : pageList.getRecords()) {
            queryFilter(eachObj);
        }
        return new ResponseObj<>(pageList, RetCode.SUCCESS);
    }

关联多表分页查询
PbBuildingController中

@TargetDataSource("ds3")
@RestController
@RequestMapping("/api/pbBuilding")
public class PbBuildingController extends BaseController {
    /**
     * 多表关联分页查询
     *
     * @param page  分页参数
     * @param model 搜索条件
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public ResponseObj> list(@ModelAttribute Page page,
                                              @ModelAttribute PbBuilding model) {
        Page pageList = service.list(page, new EntityWrapper<>(model));
        return new ResponseObj<>(pageList, RetCode.SUCCESS);
    }
}

PbBuildingService

@Service
public class PbBuildingService extends ServiceImpl {

    public Page list(Page page, Wrapper wrapper) {
        return page.setRecords(baseMapper.list(page, wrapper));
    }
}

PbBuildingMapper

@Mapper
public interface PbBuildingMapper extends BaseMapper {

    List list(RowBounds rowBounds, @Param("ew") Wrapper wrapper);
}

PbBuildingMapper.xml

  

如果仅仅查列表而不需要分页,前端不需要传current和size参数,而后台不需要Page参数

    /**
     * 返回列表
     */
    @RequestMapping(value = "/list1", method = RequestMethod.GET)
    public ResponseObj> list1(@ModelAttribute T model) {
        List listModel = service.selectList(new EntityWrapper<>(model));
        for (T eachObj : listModel) {
            queryFilter(eachObj);
        }
        return new ResponseObj<>(listModel, RetCode.SUCCESS);
    }

如果Mybatis-Plus分页查询且不返回总数total
使用// 不查询总记录数 page.setSearchCount(false);
Mybatis-Plus分页查询不返回总数total

你可能感兴趣的:(mybatis-plus分页查询)