2017-04-24 106 views
0

我使用這個代碼上傳使用resteasy在我的Java應用程序文件和它完美的作品。彈簧安置:上傳文件

import javax.ws.rs.FormParam; 
import org.jboss.resteasy.annotations.providers.multipart.PartType; 

public class FileUploadForm { 

    public FileUploadForm() { 
    } 

    private byte[] data; 

    public byte[] getData() { 
     return data; 
    } 

    @FormParam("uploadedFile") 
    @PartType("application/octet-stream") 
    public void setData(byte[] data) { 
     this.data = data; 
    } 

} 

現在我想通過使用彈簧靴和彈簧休息做同樣的事情。 我搜索了很多關於如何在春天休息時使用@FormParam@PartType,但我沒有找到任何東西。

所以,我怎樣才能使用這個類來上傳我的文件?彈簧休息時相當於@PartType@FormParam

回答

0

你想要寫的文件上傳代碼在彈簧安置它只是簡單U只需要使用多對象文件中所示下面的代碼。

@RequestMapping(value = "/upload", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA) 
    public URL uploadFileHandler(@RequestParam("name") String name, 
           @RequestParam("file") MultipartFile file) throws IOException { 

/***Here you will get following parameters***/ 
System.out.println("file.getOriginalFilename() " + file.getOriginalFilename()); 
     System.out.println("file.getContentType()" + file.getContentType()); 
     System.out.println("file.getInputStream() " + file.getInputStream()); 
     System.out.println("file.toString() " + file.toString()); 
     System.out.println("file.getSize() " + file.getSize()); 
     System.out.println("name " + name); 
     System.out.println("file.getBytes() " + file.getBytes()); 
     System.out.println("file.hashCode() " + file.hashCode()); 
     System.out.println("file.getClass() " + file.getClass()); 
     System.out.println("file.isEmpty() " + file.isEmpty()); 
/*** 
Bussiness logic 
***/ 

} 
+0

是的。從這個參數你將獲得該文件對象的所有可能的信息。 –