使用 Spring 处理 MultipartForm

编程入门 行业动态 更新时间:2024-10-13 00:33:44
本文介绍了使用 Spring 处理 MultipartForm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

此代码是用于处理上传的 RestEasy 代码:

This code is a RestEasy code for handling upload:

@Path("/fileupload") public class UploadService { @POST @Path("/upload") @Consumes("multipart/form-data") public Response create(@MultipartForm FileUploadForm form) { // Handle form } }

使用 Spring 有没有类似的东西可以像这样处理 MultipartForm?

Is there anything similar using Spring that can handle MultipartForm just like this?

推荐答案

Spring 包含了一个依赖于 commons 的 multipartresolver-fileupload,因此要使用它,您必须将其包含在您的构建中.

Spring includes has a multipartresolver that relies on commons-fileupload, so to use it you have to include it in your build.

在您的 applicationContext.xml 中

In your applicationContext.xml

<bean id="multipartResolver" class="org.springframework.web.multipartmons.CommonsMultipartResolver"> <!-- one of the properties available; the maximum file size in bytes --> <property name="maxUploadSize" value="<max file size>"/> </bean>

在您的控制器中,使用 org.springframework.web.multipart.MultipartFile.

In your controller, use org.springframework.web.multipart.MultipartFile.

@RequestMapping(method=RequestMethod.POST, value="/multipartexample") public String examplePost(@RequestParam("fileUpload") MultipartFile file){ // Handle form upload and return a view // ... }

更多推荐

使用 Spring 处理 MultipartForm

本文发布于:2023-10-28 04:42:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1535556.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Spring   MultipartForm

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!