nuzt 上传zip文件并

    @At()
    @Ok("json")
    @AdaptBy(type = UploadAdaptor.class)
    public Object addDo(@Param("sceneName") String sceneName, @Param("sceneFile") TempFile sceneFile,
                            HttpServletRequest request, HttpServletResponse response, AdaptorErrorContext err) {
           if(null==sceneName||sceneName.equals("")){
               Result.success("场景名称不能为空");
           }else{
               Sys_SceneVo u = sysSceneService.fetch(Cnd.where("sceneName", "=", sceneName));
               if (u != null)
                   return Result.error("场景名称已存在");
           }
                Sys_SceneVo sys_sceneVo = new Sys_SceneVo();
                sys_sceneVo.setSceneName(sceneName);
                sys_sceneVo.setState(1);

        try {
                // 获得zip信息
                ZipFile zipFile = new ZipFile(sceneFile.getFile());
                @SuppressWarnings("unchecked")
                Enumeration<ZipEntry> enu = (Enumeration<ZipEntry>) zipFile
                        .entries();
                while (enu.hasMoreElements()) {
                    ZipEntry zipElement = (ZipEntry) enu.nextElement();
                    InputStream read = zipFile.getInputStream(zipElement);
                   String fileName = zipElement.getName();
                    if (fileName != null && fileName.indexOf(".") != -1 && fileName.endsWith(".xml")) {
                        //xml文件
                      String secenStr=  readXml(read);
                      sys_sceneVo.setSceneContent(secenStr);

                    }else if(fileName != null && fileName.indexOf(".") != -1 && fileName.endsWith(".png")){
                        //图片文件
                         String realPath = imgSymbolRealPath + "\Symbols\ProjectImages\" + fileName;
                         String iconPath = imgSymbolPath + "/Symbols/ProjectImages/" + fileName;
                         Files.write(new File(realPath), read);
                         sys_sceneVo.setSceneIcon(iconPath);
                    }
                }
            //获取用户id
            Subject currentUser = SecurityUtils.getSubject();
            Sys_userVo user = (Sys_userVo) currentUser.getPrincipal();
            sys_sceneVo.setUserId(user.getId());
                sysSceneService.insert(sys_sceneVo);
            return Result.success("system.success");
        } catch (Exception e) {
            return Result.error("系统错误");
        } catch (Throwable e) {
            return Result.error("文件格式错误");
        }
    }
原文地址:https://www.cnblogs.com/hejunnuo/p/10578586.html