国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

SpringBoot+easypoi實現數據的Excel導出

瀏覽:112日期:2022-06-15 18:25:35

本文實例為大家分享了SpringBoot+easypoi實現數據的Excel導出的具體代碼,供大家參考,具體內容如下

maven

<dependency> <groupId>cn.afterturn</groupId> <artifactId>easypoi-spring-boot-starter</artifactId> <version>4.1.0</version></dependency>

Controller層

// 接口不需要返回值@RequestMapping(value = '/export-activity-data')public void exportActivityData(@RequestParam String activityType, @RequestParam String activityState, @RequestParam String queryValue, @RequestParam String levelValue, @RequestParam String startTime, @RequestParam String endTime, HttpServletResponse response) {try { manageService.exportActivityData(TFActivityQueryParam.builder() .activityState(activityState) .activityType(activityType) .queryValue(queryValue) .levelValue(levelValue) .startTime(''.equals(endTime) ? null : new Date(DateTime.parse(startTime).getMillis())) .endTime(''.equals(endTime) ? null : new Date(DateTime.parse(endTime).getMillis())).build(), response);} catch (IOException e) { log.info( '導出失敗', e);} }

service層

public void exportActivityData(TFActivityQueryParam param, HttpServletResponse response) throws IOException {response.setCharacterEncoding('UTF-8');response.setHeader('content-Type', 'application/vnd.ms-excel');response.setHeader('Content-Disposition','attachment;filename=' + URLEncoder.encode('活動綜合數據.xls', 'UTF-8'));val out = response.getOutputStream();List<TFActivityQueryResult> tfActivityList = getTFActivityList(param);List<TFActivityQueryResultExportDto> exportDtoList = new ArrayList<>();tfActivityList.forEach(activity -> { TFActivityQueryResultExportDto convert = TFActivityQueryResultExportDto.convert(activity); if (activity.getLevelType().equals('0')) {convert.setAffiliation('云南省'); } else {EparchyCode eparchyCode = getEparchyCodeList().stream().filter(code -> code.getEparchyCode().equals(activity.getEparchyCode())).collect(Collectors.toList()).get(0);convert.setAffiliation(eparchyCode.getEparchyShortName()); } exportDtoList.add(convert);});Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams('活動綜合數據', '活動'), TFActivityQueryResultExportDto.class, exportDtoList);log.info('workbook: {}', workbook);workbook.write(out);out.close(); }

數據bean

public class TFActivityQueryResultExportDto { @Excel(name = '活動編碼', width = 20) private String activityCode; @Excel(name = '活動名稱', width = 20) private String activityName; @Excel(name = '活動標題', width = 20) private String activityTitle; @Excel(name = '歸屬', width = 20) private String affiliation; @Excel(name = '活動類型', width = 20) private String activityType; @Excel(name = '活動時間', width = 30) private String activityTime; @Excel(name = '活動狀態', width = 20) private String activityState; @Excel(name = '備注', width = 30) private String remark; @Excel(name = '創建時間', width = 30) private String timeCreate; @Excel(name = '最新操作人', width = 30) private String operatorName; @Excel(name = '更新時間', width = 30) private String timeUpdate;}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: excel
相關文章:
主站蜘蛛池模板: 定南县| 洪泽县| 清原| 油尖旺区| 孝昌县| 庆阳市| 民勤县| 南昌市| 永泰县| 伊吾县| 乃东县| 东海县| 通渭县| 天峨县| 根河市| 贞丰县| 娄烦县| 都昌县| 右玉县| 铁力市| 龙门县| 民乐县| 扎囊县| 饶阳县| 乌拉特中旗| 绥棱县| 亳州市| 云安县| 青铜峡市| 米林县| 富源县| 灵山县| 望城县| 上饶县| 宁化县| 临沧市| 锡林浩特市| 道真| 文昌市| 赞皇县| 南川市|