@RequestMapping("/excel")
public void excel(HttpServletResponse response, HttpServletRequest request,StatisticsSearchForm statisticsSearchForm)throws Exception{
List list = statisticsService.findBySearchFrom(statisticsSearchForm);
for(StatisticsDTO statisticsDTO : list){
statisticsDTO.getId();
statisticsDTO.getNewUserCount();
statisticsDTO.getTotalPayCount();
statisticsDTO.getTotalPayNum();
statisticsDTO.getWeixinpayPayCount();
statisticsDTO.getWeixinpayPayNum();
statisticsDTO.getAlipayPayCount();
statisticsDTO.getAlipayPayNum();
statisticsDTO.getDggPayCount();
statisticsDTO.getDggPayNum();
statisticsDTO.getCreateTime();
}
FileOutputStream outputStream = null;
try {
outputStream = new FileOutputStream("d:\tongji.xls");
}catch (FileNotFoundException e){
e.printStackTrace();
}
cn.business.util.ExcelUtil util = new cn.business.util.ExcelUtil(StatisticsDTO.class);
util.exportExcel(list,"统计",outputStream);
}
outputStream = new FileOutputStream("d:\tongji.xls");
这个路径不是你客户端保存文件的路径,而是你服务器生成excel的路径,你应该把它返回到response流,设置好content-type,那么浏览器自动就会提示用户保存下载文件,并且选择路径的。