4
异常代码
private List<List<String>> head() {
List<List<String>> lists = new ArrayList<>();
List<String> head0 = new ArrayList<>();
head0.add("单位");
List<String> head1 = new ArrayList<>();
head1.add("姓名");
lists.add(head0);
lists.add(head1);
return lists;
}
private List<List<Object>> data(List<Map<String, Object>> datas) {
List<List<Object>> lists = new ArrayList<>();
for (Map<String, Object> data : datas) {
List<Object> list = new ArrayList<>();
list.add(data.get("UNIT_NAME"));
list.add(data.get("NAME"));
lists.add(list);
}
return lists;
}
@RequestMapping(value = "json/ExportExcel")
public void jsonExportExcel(Search search, HttpServletResponse response) throws IOException {
List<Map<String, Object>> maps = new ArrayList<>();
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
String fileName = URLEncoder.encode(examPoint.getName() + "-" + examSeason.getName() + "-人员详细表", "UTF-8");
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
EasyExcel.write(response.getOutputStream()).head(head()).sheet("人员信息").doWrite(data(maps));
}
异常提示
使用不创建对象的写时发现data数据类型不能是List<List