1.请求方式为:GET
2.无返回值
3.响应头设置
示例
@RequestMapping(value = "/downloadHourData", method = RequestMethod.GET)
public void downloadHourData(@RequestParam Map map, HttpServletResponse response) throws Exception {
ExcelWriter writer = ExcelUtil.getWriterWithSheet("烟厂");
map.put("city","烟厂");
List<Map> yanList = apiMonitorDataService.listByCity(map);
map.put("city","银行学校");
List<Map> yinhang = apiMonitorDataService.listByCity(map);
map.put("city","郑纺机");
List<Map> zhengfang = apiMonitorDataService.listByCity(map);
map.put("city","供水公司");
List<Map> gongshui = apiMonitorDataService.listByCity(map);
map.put("city","经开区管委");
List<Map> jingkai = apiMonitorDataService.listByCity(map);
map.put("city","四十七中");
List<Map> sishiqi = apiMonitorDataService.listByCity(map);
map.put("city","市监测站");
List<Map> shijiance = apiMonitorDataService.listByCity(map);
map.put("city","河医大");
List<Map> heyida = apiMonitorDataService.listByCity(map);
setColumnWidth(writer);
writer.write(yanList, true);
writer.setSheet("银行学校");
setColumnWidth(writer);
writer.write(yinhang,true);
writer.setSheet("郑纺机");
setColumnWidth(writer);
writer.write(zhengfang,true);
writer.setSheet("供水公司");
setColumnWidth(writer);
writer.write(gongshui,true);
writer.setSheet("经开区管委");
setColumnWidth(writer);
writer.write(jingkai,true);
writer.setSheet("四十七中");
setColumnWidth(writer);
writer.write(sishiqi,true);
writer.setSheet("市监测站");
setColumnWidth(writer);
writer.write(shijiance,true);
writer.setSheet("河医大");
setColumnWidth(writer);
writer.write(heyida,true);
response.setContentType("application/vnd.ms-excel;charset=utf-8");
//test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码
String fileName = URLEncoder.encode("郑州市近期空气质量"+ DateUtil.getDateTimeFormat(new Date()), "UTF-8");
response.setHeader("Content-Disposition","attachment;filename="+fileName+".xls");
ServletOutputStream out=response.getOutputStream();
writer.flush(out, true);
// 关闭writer,释放内存
writer.close();
//此处记得关闭输出Servlet流
IoUtil.close(out);
}