dataTable分页参数问题

currentIndex 起始索引
showCount每页多少条

        // 构建page分页参数
        Page page = new Page();
        // 设置每页显示记录数
        if (showCount == null) {
            page.setShowCount(20);
        } else {
            page.setShowCount(showCount);
        }
        // 设置查询记录起始索引
        if(currentPage==null){
            page.setCurrentIndex(0);
        }else{
            int currentIndex = (currentPage - 1) * showCount;
            page.setCurrentIndex(currentIndex);
        }
        
        // 设置检索条件
        PageData pd = new PageData();
        page.setPd(pd);

可以这么写接口

@RequestMapping(value = "/listLandProjectInfo", produces = "application/json;charset=utf-8")
    public String listProjectInfo(
            @RequestParam(value = "createUser", required = false) String createUser,
            @RequestParam(value = "areaName", required = false) String areaName,
            @RequestParam(value = "layerName", required = false) String layerName,
            @RequestParam(value = "showCount", required = false) Integer showCount,
            @RequestParam(value = "currentPage", required = false) Integer currentPage) {

        // 构建page分页参数
        Page page = new Page();
        // 设置每页显示记录数
        if (showCount == null) {
            page.setShowCount(20);
        } else {
            page.setShowCount(showCount);
        }
        // 设置查询记录起始索引
        if(currentPage==null){
            page.setCurrentIndex(0);
        }else{
            int currentIndex = (currentPage - 1) * showCount;
            page.setCurrentIndex(currentIndex);
        }
        
        
        // 设置检索条件
        PageData pd = new PageData();
        if (StringUtil.isNotBlank(createUser)) {
            pd.put("create_user", createUser);
        }
        if (StringUtil.isNotBlank(areaName)) {
            pd.put("area_name", areaName);
        }
        if (StringUtil.isNotBlank(layerName)) {
            pd.put("layer_name", layerName);
        }
        page.setPd(pd);

        JSONObject resultJson = new JSONObject();
        try {
            // 根据条件查询数据
            List<PageData> list = landProjectInfoService.dataListPage(page);
            resultJson.put("RespCode", Const.REQUEST_CODE_SUCCESS);
            resultJson.put("RespMessage",
                    Const.REQUEST_MSG_MAP.get(Const.REQUEST_CODE_SUCCESS));
            resultJson.put("Body", JSONArray.fromObject(list));
        } catch (Exception e) {
            e.printStackTrace();
            resultJson.put("RespCode", Const.REQUEST_CODE_ERROR);
            resultJson.put("RespMessage",
                    Const.REQUEST_MSG_MAP.get(Const.REQUEST_CODE_ERROR));
            resultJson.put("ErrorMessage", e.getMessage());
        }
        return resultJson.toString();
    }
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容