需求:
前台要导出excel表格,开始用的bootstrap table的tableExport.js插件导出但是只能导出当前页的数据,so 又改到了后台导出(悲催)
导出按钮:
<button type="button" onClick ="supplierOutIncheckExport()">盘库单报(总部)表</button>
JavaScript代码:
function supplierOutIncheckExport(){
var url =inventoryObj.initStoreInventorycheckExportUrl;//请求后台要导出的地址
//构建一个虚拟的form 表单并设置表单ID和名称提交方式等
exportForm = document.createElement("form");
exportForm.setAttribute('id','StorageInventoryVo')
exportForm.setAttribute('name','StorageInventoryVo');
exportForm.setAttribute("action", url);
exportForm.setAttribute("contentType", 'application/x-xls');
exportForm.setAttribute("hidden", true);
exportForm.setAttribute("method", "post");
//构建一个虚拟的input框并设置属性类型和值,并添入form表单中
var userId = document.createElement("input");
userId.type = "text";
userId.name = "staffId";
userId.value = currentUser.userId;
exportForm.appendChild(userId);
//构建一个虚拟的input框并设置属性类型和值,并添入form表单中
var fileName = document.createElement("input");
fileName.type = "text";
fileName.name = "fileName";
fileName.value = "库盘单(总部)报表.xls";
exportForm.appendChild(fileName);
//表单提交
document.body.appendChild(exportForm);
exportForm.submit();
}
java后台代码:
/**
*
* @Author: ruanyanghui
* @Company: xxxx
* @Description: 导出实时库存
* @date 2018/12/6 14:35
*/
@PostMapping("/storageexport")
public void getstorageexport(StorageInventoryVo vo, HttpServletResponse response) {
vo = vo.getParams();
St