精致小操作合集

DBC 1.4K 0

一、精致小操作合集

1、避免导出时候看到一堆乱码

 @GetMapping(value = "/export",produces = "application/octet-stream")

2、通过Post传参到后端,如果是实体类需要这样子传,和Params有所区别

    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")

二、高性能map遍历

        // 高性能遍历操作
        Set<Map.Entry<Integer, List<ProjectFiles>>> entries = stateMap.entrySet();
        for (Map.Entry<Integer, List<ProjectFiles>> entry : entries) {

        }

自定义分页器

    // 自定义分页器
    private Page<PovertyMonitoringHouseholdSectionVO> getMonitorPage(PageParam pageParam, List<PovertyMonitoringHouseholdSectionVO> resultLists) {
        //当前页
        int current = pageParam.getPageNumber();
        //每页数据条数
        int size = pageParam.getPageSize();
        Page<PovertyMonitoringHouseholdSectionVO> page = new Page<>(current, size);
        int count = resultLists.size();
        List<PovertyMonitoringHouseholdSectionVO> pageList = new ArrayList<>();
        //计算当前页第⼀条数据的下标
        int currId = current > 1 ? (current - 1) * size : 0;
        for (int i = 0; i < size && i < count - currId; i++) {
            pageList.add(resultLists.get(currId + i));
        }
        page.setSize(size);
        page.setCurrent(current);
        page.setTotal(count);
        //计算分页总页数
        page.setPages(count % 10 == 0 ? count / 10 : count / 10 + 1);
        page.setRecords(pageList);
        return page;

    }

发表评论 取消回复
表情 图片 链接 代码

分享