表格图:
jsp:
后台:
@RequiresPermissions("shwindow:advertisementPutInList:view")
@RequestMapping(value = "export", method=RequestMethod.POST)
@ResponseBody
public String exportFile(AdvertisementPutInList advertisementPutInList,HttpServletRequest request,String[] oddNumbers, HttpServletResponse response, RedirectAttributes redirectAttributes) {
List<AdvertisementPutInList> list=new ArrayList<AdvertisementPutInList>();
try {
String fileName = "广告单数据"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
if(oddNumbers!=null){//用户有勾选需要导出的数据记录
for(int i=0;i<oddNumbers.length;i++){
System.out.println(oddNumbers[i]+"&&&");
AdvertisementPutInList apils=advertisementPutInListService.getByDNum(oddNumbers[i]);
//Page<AdvertisementPutInList> page =advertisementPutInListService.findAdvertisementPutInList(new Page<AdvertisementPutInList>(request, response, -1), apils);
list.add(apils);
}
ExportExcel ExportExcel=new ExportExcel("广告单数据", AdvertisementPutInList.class).setDataList(list).write(response, fileName).dispose();
}else {//用户没有勾选,则导出页面展示的数据记录
Page<AdvertisementPutInList> page = advertisementPutInListService.findAdvertisementPutInList(new Page<AdvertisementPutInList>(request, response, -1), advertisementPutInList);
new ExportExcel("广告单数据", AdvertisementPutInList.class).setDataList(page.getList()).write(response, fileName).dispose();
}
} catch (Exception e) {
addMessage(redirectAttributes, "导出失败!失败信息:"+e.getMessage());
}
return "redirect:" + adminPath+"/shwindow/advertisementPutInList/?repage";
}