导包:
1
2
3 cn.afterturn
4 easypoi-base
5 3.2.0
6
7
8 cn.afterturn
9 easypoi-web
10 3.2.0
11
12
13 cn.afterturn
14 easypoi-annotation
15 3.2.0
16
一:文件下载
1:前台准备导出按钮
1 数据导出
1.2 准备好view(beanName的视图解析器)
在applicationContext-mvc.xml
1.3:在DownloadController完成后台导出
/*** 导出就是下载(下载就是把一个流 从服务器端 -> 客户端)
*
* EasypoiSingleExcelView : 注解导出的view*/@RequestMapping("/export")publicString export(EmployeeQuery query,ModelMap map, HttpServletRequest request){//根据查询条件拿到所有数据
List list =employeeService.queryAll(query);//导出的属性
ExportParams params = new ExportParams("员工数据", "员工表", ExcelType.XSSF);//params.setFreezeCol(2); 冻结//request:获取到真实路径
String realPath = request.getServletContext().getRealPath("");
System.out.println(realPath);
list.forEach(e->{
e.setHeadImage(realPath+e.getHeadImage());
});
map.put(NormalExcelConstants.DATA_LIST, list);//数据集合
map.put(NormalExcelConstants.CLASS, Employee.class);//导出实体
map.put(NormalExcelConstants.PARAMS, params);//参数
map.put(NormalExcelConstants.FILE_NAME, "employee");//文件名称//