文件导出步骤:
引入问价导入导出的相关java文件; 如需要可联系qq
1、建立导出的按钮
2、导出时的提示
$("#btnExport").click(function(){
top.$.jBox.confirm("确认要导出运营数据吗?","系统提示",function(v,h,f){
if(v=="ok"){
var searchAction = $("#searchForm").attr("action");
$("#searchForm").attr("action","${ctx}/operation/operationData/export");//路径
$("#searchForm").submit();
$("#searchForm").attr("action",searchAction);
}
},{buttonsFocus:1});
top.$('.jbox-body .jbox-icon').css('top','55px');
});
3、在控制器中方法
/**
* 导出数据(有实体)
*
* @return
*/
@RequiresPermissions("operation:operationData:view")
@RequestMapping(value = "export", method=RequestMethod.POST)
public String exportFile(OperationData operationData, HttpServletRequest request, HttpServletResponse response, Model model, RedirectAttributes redirectAttributes) {
try {
String fileName = "文件名称"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
List list = operationDataService.findList(operationData);
new ExportExcel("
文件名称(起始时
间:"+StringUtils.replaceNull(DateUtils.formatDate(operationData.getBeginDt(), "yyyy-
MM-dd"), "不限制")+",结束时
间:"+StringUtils.replaceNull(DateUtils.formatDate(operationData.getEndDt(), "yyyy-
MM-dd"), "不限
制")+")", OperationData.class).setDataList(list).write(response, fileName).dispose();
return null;
} catch (Exception e) {
addMessage(redirectAttributes, "导出运营数据失败!失败信息:"+e.getMessage());
}
return "redirect:" + adminPath + "/modules/operation/operationDataList?repage";
}
/**
* 导出数据(无实体)
*
* @return
*/
@RequiresPermissions("operation:projectOperation:view")
@RequestMapping(value = "export", method=RequestMethod.POST)
public String exportFile(ProjectBaseInfo projectBaseInfo, HttpServletRequest request, HttpServletResponse response, Model model, RedirectAttributes redirectAttributes) {
try {
String fileName = "导出的文件名称"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
List> list = projectBaseInfoService.findProjectOperationListNoPage(projectBaseInfo);
LinkedHashMap fieldMap = new LinkedHashMap();
fieldMap.put("导出列", "列名称");
、、、、、、、、、、、、、、、、、
new ExportExcel("文件名称", fieldMap).setDataList(list).write(response, fileName).dispose();
return null;
} catch (Exception e) {
addMessage(redirectAttributes, "导出项目财务数据失败!失败信息:"+e.getMessage());
}
return "redirect:" + adminPath + "/modules/operation/projectOperationList?repage";
}
4、在导出的pojo中加入注解
在get上加入@ExcelField(title="名称", align=2, sort=20)