三、关于easypoi导入excel-------------简单应用

1.导入依赖

三、关于easypoi导入excel-------------简单应用_第1张图片


    org.jeecg
    easypoi-base
    2.3.1


    org.jeecg
    easypoi-web
    2.3.1


    org.jeecg
    easypoi-annotation
    2.3.1

 2.实体类打上注解

三、关于easypoi导入excel-------------简单应用_第2张图片

@Excel(name = "PLC读取地址") 实体类字段的注解(这个name和表格列要一致)

 

3.controller层的代码

三、关于easypoi导入excel-------------简单应用_第3张图片

三、关于easypoi导入excel-------------简单应用_第4张图片 

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 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();

        }

你可能感兴趣的:(三、关于easypoi导入excel-------------简单应用)