ExportController.java
3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package com.bckefu.controller;
import com.bckefu.entity.ContactsEntity;
import com.bckefu.excel.entity.ExportParams;
import com.bckefu.excel.entity.enmus.ExcelType;
import com.bckefu.excel.entity.params.ExcelExportEntity;
import com.bckefu.excel.entity.vo.ExcelConstants;
import com.bckefu.excel.handler.inter.IExcelExportServer;
import com.bckefu.excel.view.BaseView;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author : caoliang
* @date : 2017/11/6:下午3:51
*/
@RestController
@RequestMapping("export")
public class ExportController {
@Autowired
IExcelExportServer excelExportServer;
@ApiOperation(value = "导出bigData" , tags = "1.2.1")
@GetMapping("bigData")
public void downloadByPoiBaseView(ModelMap map, HttpServletRequest request,
HttpServletResponse response) {
ExportParams params = new ExportParams("测试sheetName", ExcelType.XSSF);
//params.setFreezeCol(0); //冻结列
params.setFreezeRow(1); //冻结行
map.put(ExcelConstants.CLASS, ContactsEntity.class);
map.put(ExcelConstants.PARAMS, params);
//就是我们的查询参数,会带到接口中,供接口查询使用
map.put(ExcelConstants.DATA_PARAMS, new HashMap<String, String>());
map.put(ExcelConstants.DATA_INTER, excelExportServer);
BaseView.render("测试下载", map, request, response, ExcelConstants.POI_BIG_EXCEL_VIEW);
}
@ApiOperation(value = "导出mapData" , tags = "1.2.2")
@GetMapping("mapData")
public void mapData(ModelMap modelMap, HttpServletRequest request,
HttpServletResponse response) {
List<ExcelExportEntity> entity = new ArrayList<ExcelExportEntity>();
ExcelExportEntity excelentity = new ExcelExportEntity("姓名", "name");
excelentity.setNeedMerge(true);
entity.add(excelentity);
entity.add(new ExcelExportEntity("性别", "sex"));
excelentity = new ExcelExportEntity(null, "students");
List<ExcelExportEntity> temp = new ArrayList<ExcelExportEntity>();
temp.add(new ExcelExportEntity("姓名", "name"));
temp.add(new ExcelExportEntity("性别", "sex"));
excelentity.setList(temp);
entity.add(excelentity);
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> map;
for (int i = 0; i < 10; i++) {
map = new HashMap<String, Object>();
map.put("name", "1" + i);
map.put("sex", "2" + i);
List<Map<String, Object>> tempList = new ArrayList<Map<String, Object>>();
tempList.add(map);
tempList.add(map);
map.put("students", tempList);
list.add(map);
}
ExportParams params = new ExportParams("2412312", "测试", ExcelType.XSSF);
params.setFreezeCol(2);
modelMap.put(ExcelConstants.MAP_LIST, list);
modelMap.put(ExcelConstants.ENTITY_LIST, entity);
modelMap.put(ExcelConstants.PARAMS, params);
BaseView.render("map导出",modelMap, request, response, ExcelConstants.MAP_EXCEL_VIEW);
}
}