栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

java用easypoi完成数据导入(结合layui)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

java用easypoi完成数据导入(结合layui)

第一步:在pom文件中导入如下依赖
    
            cn.afterturn
            easypoi-base
            3.2.0
        
        
            cn.afterturn
            easypoi-web
            3.2.0
        
        
            cn.afterturn
            easypoi-annotation
            3.2.0
        
第二步在实体需要导入的字段上面添加如下注解
import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelTarget;
-------导包

@Excel(name = "配置项值")        ----excel表头名
@TableField("PRIMARILY")        ----数据库中的字段名
第三步代码
public JSONObject uploadExcel(MultipartFile multipartFile, HttpServletResponse response) {
        try {
            ImportParams params = new ImportParams();
            params.setHeadRows(1);
            List result = ExcelImportUtil.importExcel(multipartFile.getInputStream(), grantConfig.class, params);
            //创建一个集合用于存放map数据
            List> hashMaps = new ArrayList<>();
            HashMap map;
            for (grantConfig grantConfig : result) {
                map = new HashMap<>();
                map.put("primarily", grantConfig.getPrimarily());
                map.put("critical", grantConfig.getCritical());
                map.put("key", grantConfig.getKey());
                map.put("remarks", grantConfig.getRemarks());
                hashMaps.add(map);
            }
            insert(hashMaps);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("state", "success");
           return
按钮

实现
//上传文件
        upload.render({
            elem: '#importFile',
            url: '/grantConfig/uploadGrantFile',
            accept: 'file',
            done: function (res) {
                if (res.state == 'success') {
                    layer.msg("导入成功", {icon: 1})
                } else {
                    layer.msg("导入失败", {icon: 2})
                }
            }
        });

------此段代码要放在layui.use
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/854941.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号