标签:value string bool art EDA date input div str
控制层代码:
@PostMapping("/import") public RespBean importData(MultipartFile file) throws IOException {
//从上传的文件里解析出Position集合 List<Position> list=POIUtils.parseFile(file); return RespBean.ok("ok"); }
然后在POIUtils中定义parseFile方法,代码如下:
public static List<Position> parseFile(MultipartFile file) { List<Position> list = new ArrayList<>(); try { HSSFWorkbook workbook = new HSSFWorkbook(file.getInputStream()); HSSFSheet sheet = workbook.getSheetAt(0); int rows = sheet.getPhysicalNumberOfRows(); for (int i = 1; i < rows; i++) { HSSFRow r = sheet.getRow(i); double numericCellValue = r.getCell(0).getNumericCellValue(); String name = r.getCell(1).getStringCellValue(); Date createdate = r.getCell(2).getDateCellValue(); boolean enabled = "是".equals(r.getCell(3).getStringCellValue()); Position position = new Position(); position.setEnabled(enabled); position.setCreatedate(createdate); position.setName(name); position.setId((int) numericCellValue); list.add(position); } } catch (IOException e) { e.printStackTrace(); } System.out.println(list); return list; }
然后就库将list保存到数据库中便可!!
标签:value string bool art EDA date input div str
原文地址:https://www.cnblogs.com/zzjlxy-225223/p/11380241.html