使用mybatis-plus基于BaseMapper的Page对象按条件分页查询
controller层
/** * 分页列表查询 * * @param role * @param pageNo * @param pageSize * @param req * @return */ @RequestMapping(value = "/list", method = RequestMethod.POST) public ApiResult queryPageList(@RequestBody SysRoleVo sysRoleVo) { return service.queryPageList(sysRoleVo); }
service层 带有模糊查询
/* 分页查询 */ public ApiResult queryPageList(SysRoleVo sysRoleVo) { try { QueryWrapper<SysRole> queryWrapper = new QueryWrapper<>(); queryWrapper.like("role_name", sysRoleVo.getRoleName()); Page<SysRole> page = new Page<SysRole>(sysRoleVo.getPage(), sysRoleVo.getPageSize()); IPage<SysRole> pageList = baseMapper.selectPage(page, queryWrapper); return ApiResult.success(pageList); } catch (Exception e) { log.error("查询失败", e); return ApiResult.fail("操作失败"); } }