網(wǎng)站的音樂鏈接怎么做現(xiàn)在有什么技能培訓(xùn)班
今天做報表導(dǎo)出,網(wǎng)上找了很多導(dǎo)出的方法,最后總結(jié)發(fā)現(xiàn)以下方法是最簡便,更易維護(hù)的導(dǎo)出方法,下面來分享給大家。
1、首先引入相關(guān)依賴
<!--EasyPoi 報表--><dependency><groupId>cn.afterturn</groupId><artifactId>easypoi-spring-boot-starter</artifactId><version>4.4.0</version></dependency>
2、導(dǎo)出實體映射類
@Data
public class StudentReportResponse implements Serializable {@Excel(name = "性別", width = 12)private String gender;@Excel(name = "姓名", width = 15)private String name;
}
3、Controller層代碼
@GetMapping("/exportReport")@ApiOperation("導(dǎo)出學(xué)生報表")public void export(ModelMap map, HttpServletResponse response, HttpServletRequest request){try {List<StudentReportResponse> studentReportData = new ArrayList<>();StudentReportResponse student = new StudentReportResponse();student.setGender("男");student.setName("測試用戶");studentReportData.add(student);ExportParams params = new ExportParams("學(xué)生報表", "學(xué)生報表", ExcelType.HSSF);map.put(NormalExcelConstants.DATA_LIST, studentReportData);map.put(NormalExcelConstants.CLASS, StudentReportResponse.class);map.put(NormalExcelConstants.PARAMS, params);map.put(NormalExcelConstants.FILE_NAME, "學(xué)生報表");PoiBaseView.render(map, request, response, NormalExcelConstants.EASYPOI_EXCEL_VIEW);} catch (Exception e) {logger.error("導(dǎo)出學(xué)生報表報錯:", e);}}
怎么樣,是不是很簡潔,可讀性很高 ?( ′・?・` )