2017-04-24 102 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

是的。从这个参数你将获得该文件对象的所有可能的信息。 –