其他分享
首页 > 其他分享> > file

file

作者:互联网

if (logoSimple != null) {
String name = logoSimple.getName();
File file = null;
file = File.createTempFile(“logoSimple”, null);
logoSimple.transferTo(file);
JFSUtil.saveFileToJFS(“tenantLogo/logoSimple.png”, file);
file.deleteOnExit();
}

    } catch (IOException e) {
        e.printStackTrace();
    }

// JFSUtil.existFile("");
result = ResultUtil.getSuccessResult(“保存成功”);
return result;

}


@RequestMapping("/filesUpload")
//requestParam要写才知道是前台的那个数组
public String filesUpload(@RequestParam("myfiles") MultipartFile[] files,
                          HttpServletRequest request) {
    List<String> list = new ArrayList<String>();
    if (files != null && files.length > 0) {
        for (int i = 0; i < files.length; i++) {
            MultipartFile file = files[i];
            // 保存文件
            list = saveFile(request, file, list);

        }
    }
    //写着测试,删了就可以
    for (int i = 0; i < list.size(); i++) {
        System.out.println("集合里面的数据" + list.get(i));
    }
    return "index";//跳转的页面
}

private List<String> saveFile(HttpServletRequest request,
                              MultipartFile file, List<String> list) {
    // 判断文件是否为空
    if (!file.isEmpty()) {
        try {
            // 保存的文件路径(如果用的是Tomcat服务器,文件会上传到\\%TOMCAT_HOME%\\webapps\\YourWebProject\\upload\\文件夹中
            // )
           /* String filePath = request.getSession().getServletContext()
                    .getRealPath("/")
                    + "upload/" + file.getOriginalFilename();*/
            String filePath =  "C:/Users/likai196/Desktop/gg/upload/" + file.getOriginalFilename();
            list.add(file.getOriginalFilename());
            File saveDir = new File(filePath);
            if (!saveDir.getParentFile().exists())
                saveDir.getParentFile().mkdirs();

            // 转存文件
            file.transferTo(saveDir);
            return list;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return list;
}

标签:files,return,logoSimple,list,saveDir,file
来源: https://blog.csdn.net/likaiCSDN/article/details/96478952