1.导入依赖
<dependency> <groupId>org.jeecg</groupId> <artifactId>easypoi-base</artifactId> <version>2.3.1</version> </dependency> <dependency> <groupId>org.jeecg</groupId> <artifactId>easypoi-web</artifactId> <version>2.3.1</version> </dependency> <dependency> <groupId>org.jeecg</groupId> <artifactId>easypoi-annotation</artifactId> <version>2.3.1</version> </dependency>
2.实体类打上注解
@Excel(name = "PLC读取地址") 实体类字段的注解(这个name和表格列要一致)
3.controller层的代码
controller层的上传代码:
@RequestMapping(value="/upload",method=RequestMethod.POST) public void upload(@RequestParam("onlinefilename")MultipartFile file, HttpServletRequest request) throws FileNotFoundException, IOException { ImportParams params = new ImportParams(); params.setTitleRows(0); params.setHeadRows(1); List<PointConfigtempletEntity> list; try { //excel的数据 list = ExcelImportUtil.importExcel( file.getInputStream(), PointConfigtempletEntity.class, params); System.out.println(list.size()); for (PointConfigtempletEntity entity :list) { entity.setId(IdGenUtils.uuid()); entity.setUpdateDate(new Date()); } // //批量导入 接口 pointConfigtempletService.saveBybatch(list); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }