小编Har*_*.N.的帖子

如何在邮递员中上传文件和json数据

我正在使用Spring MVC,这是我的方法:

/** 
* Upload single file using Spring Controller 
*/ 
@RequestMapping(value = "/uploadFile", method = RequestMethod.POST) 
public @ResponseBody ResponseEntity<GenericResponseVO<? extends IServiceVO>> uploadFileHandler(@RequestParam("name") String name, @RequestParam("file") MultipartFile file,HttpServletRequest request, HttpServletResponse response) { 
    if (!file.isEmpty()) { 
        try { 
            byte[] bytes = file.getBytes();     
            // Creating the directory to store file 
            String rootPath = System.getProperty("catalina.home"); 
            File dir = new File(rootPath + File.separator + "tmpFiles"); 
            if (!dir.exists()) 
                dir.mkdirs();     
            // Create the file on server 
            File serverFile = new File(dir.getAbsolutePath() + File.separator + name); 
            BufferedOutputStream …
Run Code Online (Sandbox Code Playgroud)

java json spring-mvc postman

82
推荐指数
16
解决办法
19万
查看次数

标签 统计

java ×1

json ×1

postman ×1

spring-mvc ×1