• 分页在controller/service/dao上各层的写法。


    view:

        @Authorize
        @ApiOperation(value = "学期列表")
        @GetMapping(value = "/list/page")
        public Result<PageBean<BaseSemesterVo>> list(@ApiParam("入口验证") SignModel signModel,
                                                     @ApiParam(value = "第几页", required = true) @RequestParam(defaultValue = AppConstant.CURRPAGE) Integer currPage,
                                                     @ApiParam(value = "每页大小", required = true) @RequestParam(defaultValue = AppConstant.PAGESIZE) Integer pageSize,
                                                     @ApiParam("查询条件") BaseSemesterCondition semesterCondition) throws Exception {
            return ResultGenerator.genSuccessResult(baseSemesterService.findAllByCondition(semesterCondition,currPage, pageSize));
        }
    

    service:

        PageBean<BaseSemesterVo> findAllByCondition(BaseSemesterCondition semesterCondition, Integer currPage, Integer pageSize);
    
    impl#:
        @Override
        public PageBean<BaseSemesterVo> findAllByCondition(BaseSemesterCondition semesterCondition, Integer currPage, Integer pageSize) {
            PageHelper.startPage(currPage, pageSize);
            List<BaseSemesterVo> semesterVoList = baseSemesterMapper.selectAllByCondition(semesterCondition);
            PageBean pageBean = new PageBean(semesterVoList);
            pageBean.setList(semesterVoList);
    
            return pageBean;
        }
    

    dao:

        List<BaseSemesterVo> selectAllByCondition(BaseSemesterCondition semesterCondition);
    

    comm:

    @Data
    public class PageBean<T> implements Serializable {
        private int pageNum;                // 第几页
        private int pageSize;               // 每页记录数
        private int size;                   // 当前页的数量 <= pageSize,该属性来自ArrayList的size属性
        private long total;                 // 总记录数
        private int pages;                  // 总页数
        private List<T> list;               // 结果集
    //    private boolean isFirstPage;        // 是否第一页
    //    private boolean isLastPage;         // 是否最后一页
    //    private boolean hasPreviousPage;    // 是否有上一页
    //    private boolean hasNextPage;        // 是否有下一页
    
        public PageBean() {
    //        this.isFirstPage = false;
    //        this.isLastPage = false;
    //        this.hasPreviousPage = false;
    //        this.hasNextPage = false;
        }
    
        /**
         * 包装Page对象,因为直接返回Page对象,在JSON处理以及其他情况下会被当成List来处理,而出现一些问题。
         *
         * @param list page结果
         */
        public PageBean(List<T> list) {
    //        this.isFirstPage = false;
    //        this.isLastPage = false;
    //        this.hasPreviousPage = false;
    //        this.hasNextPage = false;
            if (list instanceof Page) {
                Page page = (Page) list;
                this.pageNum = page.getPageNum();
                this.pageSize = page.getPageSize();
                this.pages = page.getPages();
                this.list = page;
                this.size = page.size();
                this.total = page.getTotal();
            } else if (list instanceof Collection) {
                this.pageNum = 1;
                this.pageSize = list.size();
                this.pages = 1;
                this.list = list;
                this.size = list.size();
                this.total = (long) list.size();
            }
    
    //        if (list instanceof Collection) {
    //            this.judgePageBoudary();
    //        }
        }
    
    //    private void judgePageBoudary() {
    //        this.isFirstPage = this.pageNum == 1;
    //        this.isLastPage = this.pageNum == this.pages;
    //        this.hasPreviousPage = this.pageNum > 1;
    //        this.hasNextPage = this.pageNum < this.pages;
    //    }
    }
    
    
    
    public interface AppConstant {
        // 第一页
        String CURRPAGE = "1";
    
        // 每页记录数
        String PAGESIZE = "20";
    }
    
    
  • 相关阅读:
    逆波兰表达式、波兰表达式【数据结构与算法】
    Python下所有所有异常处理办法
    修改jenkins源为国内源
    [sql Server]除非另外还指定了TOP 或 FOR XML,否则,ORDER BY 子句在视图、内联函数、派生表、子查询和公用表表达式中无效
    原创 CDH 6.2.1 装 es 怎么配置 master ???
    contos7开启端口,关闭防火墙
    分布式下session共享问题和解决
    伪原创api接口[HTTP]
    AI写作机器人基于GPT-3
    基于AI的自动改写文章的软件
  • 原文地址:https://www.cnblogs.com/kltsee/p/14842118.html
Copyright © 2020-2023  润新知