解决商品导出excel失败的bug

This commit is contained in:
季圣华
2019-07-30 23:13:32 +08:00
parent 0e46a9f21d
commit 5e1a899f7b
2 changed files with 16 additions and 13 deletions

View File

@@ -198,15 +198,13 @@ public class MaterialController {
* @return * @return
*/ */
@GetMapping(value = "/exportExcel") @GetMapping(value = "/exportExcel")
public BaseResponseInfo exportExcel(@RequestParam("name") String name, public void exportExcel(@RequestParam("name") String name,
@RequestParam("model") String model, @RequestParam("model") String model,
@RequestParam("categoryIds") String categoryIds, @RequestParam("categoryIds") String categoryIds,
HttpServletRequest request, HttpServletResponse response)throws Exception { HttpServletRequest request, HttpServletResponse response) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
String message = "成功";
try { try {
List<MaterialVo4Unit> dataList = materialService.findByAll(name, model, categoryIds); List<MaterialVo4Unit> dataList = materialService.findByAll(StringUtil.toNull(name), StringUtil.toNull(model),
StringUtil.toNull(categoryIds));
String[] names = {"品名", "类型", "型号", "安全存量", "单位", "零售价", "最低售价", "预计采购价", "批发价", "备注", "状态"}; String[] names = {"品名", "类型", "型号", "安全存量", "单位", "零售价", "最低售价", "预计采购价", "批发价", "备注", "状态"};
String title = "商品信息"; String title = "商品信息";
List<String[]> objects = new ArrayList<String[]>(); List<String[]> objects = new ArrayList<String[]>();
@@ -229,16 +227,9 @@ public class MaterialController {
} }
File file = ExcelUtils.exportObjectsWithoutTitle(title, names, title, objects); File file = ExcelUtils.exportObjectsWithoutTitle(title, names, title, objects);
ExportExecUtil.showExec(file, file.getName(), response); ExportExecUtil.showExec(file, file.getName(), response);
res.code = 200;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
message = "导出失败";
res.code = 500;
} finally {
map.put("message", message);
res.data = map;
} }
return res;
} }
/** /**

View File

@@ -215,4 +215,16 @@ public class StringUtil {
} }
return value; return value;
} }
public static String toNull(String value) {
if(("").equals(value)) {
value = null;
}
return value;
}
public static void main(String[] args) {
int i = 10/3;
System.out.println(i);
}
} }