@ResponseBody
@RequestMapping(produces = "text/html;charset=UTF-8", value="/download", method=RequestMethod.GET)
public String doDownload(HttpServletResponse response){
Map<String, String> map = new HashMap<String,String>();
String[] header={"联系方式","姓名","状态"};
List<Phone> list = new ArrayList<Phone>();
for (int i = 0; i < 20; i++) {
Phone phone = new Phone();
phone.setName("name"+i);
phone.setPhone("1343299477"+i);
phone.setStatus(UserStatus.FAILURE);
list.add(phone);
}
Workbook wb = WriteExcelUtil.createWorkbook(list,header);
OutputStream out = null;
try {
out = response.getOutputStream();
String showFileName = "MobileList.xls";
response.addHeader("Content-disposition","attachment; filename=\"" + showFileName + "\"");
response.setContentType("text/html;charset=UTF-8");
wb.write(out);
} catch (IOException e) {
e.printStackTrace();
}finally {
//关闭流
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return "";
}