自定义sql分页实现

最后更新于:2022-04-02 07:12:01

自定义sql分页实现 === ### (1)mapper 接口以及 xml ``` /** * @Description: 系统通告表 * @Author: jeecg-boot * @Date: 2019-01-02 * @Version: V1.0 */ public interface SysAnnouncementMapper extends BaseMapper { List querySysCementListByUserId(Page page, String userId,String msgCategory); } ``` 这里要注意的是,这个 Page page 是必须要有的,否则 Mybatis-Plus 无法为你实现分页。 ``` ``` ### (3) service 实现 ``` @Override public Page querySysCementPageByUserId(Page page, String userId,String msgCategory) { return page.setRecords(sysAnnouncementMapper.querySysCementListByUserId(page, userId, msgCategory)); } ``` ### (4) controller 实现 ``` @RequestMapping(value = "/list", method = RequestMethod.GET) public Result> queryPageList(SysAnnouncement sysAnnouncement, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, HttpServletRequest req) { Result> result = new Result>(); Page pageList = new Page(pageNo,pageSize); pageList = sysAnnouncementService.querySysCementPageByUserId(pageList,"","1");//通知公告消息 log.info("查询当前页:"+pageList.getCurrent()); log.info("查询当前页数量:"+pageList.getSize()); log.info("查询结果数量:"+pageList.getRecords().size()); log.info("数据总数:"+pageList.getTotal()); result.setSuccess(true); result.setResult(pageList); return result; } ```
';