controller層展示
@RequestMapping(value = "/batch", method = RequestMethod.POST) public HttpResult batchAdd(@RequestAttribute User user, @RequestParam MultipartFile file) throws IOException, BiffException { HttpResult result = null; Sheet sheet = null; logService.add(new SystemLog(user, "報表上傳", "批量上傳")); Workbook workbook = null; List<String> errors = null; ReportParams reportParams = null; try { workbook = Workbook.getWorkbook(file.getInputStream()); sheet = workbook.getSheet(0); errors = new ArrayList<>(); reportParams = new ReportParams(); } catch (BiffException e) { e.printStackTrace(); return HttpResult.newError("提交的文件不是真實.xls格式!請將文件另存爲.xls格式之後再提交!"); } for (int i = 1; i < sheet.getRows(); i++) { Cell[] cells = sheet.getRow(i); if(!cells[0].getContents().isEmpty()){ reportParams.setCompanyCode(cells[0].getContents()); reportParams.setCustomerNumber(cells[1].getContents()); reportParams.setCustomerName(cells[2].getContents()); reportParams.setMaterialNumber(cells[3].getContents()); reportParams.setMaterialName(cells[4].getContents()); reportParams.setTradeName(cells[5].getContents()); reportParams.setSpecifications(cells[6].getContents()); reportParams.setManufacturer(cells[7].getContents()); reportParams.setUnit(cells[8].getContents()); reportParams.setNumber(Double.parseDouble(cells[9].getContents())); reportParams.setUploadPeople(cells[10].getContents()); result = reportService.add(reportParams); int status = (int) result.get("status"); if (status != 200) { errors.add(String.valueOf(result.get("msg"))); return result.add("errors", errors); } } } return result.add("errors", errors); }
實體類展示
public class ReportParams { private int id; private String companyCode; private String customerNumber; private String customerName; private String materialNumber; private String materialName; private String tradeName; private String specifications; private String manufacturer; private String Unit; private Double number; private String uploadPeople; private List<String> time = new ArrayList<>(); public List<String> getTime() { return time; } public void setTime(List<String> time) { this.time = time; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getCompanyCode() { return companyCode; } public void setCompanyCode(String companyCode) { this.companyCode = companyCode; } public String getCustomerNumber() { return customerNumber; } public void setCustomerNumber(String customerNumber) { this.customerNumber = customerNumber; } public String getCustomerName() { return customerName; } public void setCustomerName(String customerName) { this.customerName = customerName; } public String getMaterialNumber() { return materialNumber; } public void setMaterialNumber(String materialNumber) { this.materialNumber = materialNumber; } public String getMaterialName() { return materialName; } public void setMaterialName(String materialName) { this.materialName = materialName; } public String getTradeName() { return tradeName; } public void setTradeName(String tradeName) { this.tradeName = tradeName; } public String getSpecifications() { return specifications; } public void setSpecifications(String specifications) { this.specifications = specifications; } public String getManufacturer() { return manufacturer; } public void setManufacturer(String manufacturer) { this.manufacturer = manufacturer; } public String getUnit() { return Unit; } public void setUnit(String unit) { Unit = unit; } public Double getNumber() { return number; } public void setNumber(Double number) { this.number = number; } public String getUploadPeople() { return uploadPeople; } public void setUploadPeople(String uploadPeople) { this.uploadPeople = uploadPeople; } }