我的控制器看起来像这样
@RequestMapping (value = { "/link_multiple" } , method =
RequestMethod.POST)
public ModelAndView linkMultipleVideo(
@RequestParam ("csv_file") final MultipartFile file) {
这是我的自由标记模板
<input type="file" class="csv_file" name="csv_file" id="csv_file" accept=".csv"/>
<a class="file-link" href="javascript:void(0);">Choose File</a>
<span class='input-file-select'></span>
</div>
我还添加了多部分解析程序配置到
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="2097152"/>
</bean>
还添加了在网络过滤器下方.xml
<filter>
<filter-name>multipartFilter</filter-name>
<filter-class>org.springframework.web.multipart.support.MultipartFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>multipartFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
以下是我得到的异常。
org.springframework.web.bind.MissingServletRequestParameterException: Required MultipartFile parameter 'csv_file' is not present
[tomcat:launch] at org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:255)
[tomcat:launch] at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:95)
[tomcat:launch] at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:79)
[tomcat:launch] at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:157)
[tomcat:launch] at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:124)
[tomcat:launch] at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
我通过从网络中删除过滤器来让它工作.xml。
<filter>
<filter-name>multipartFilter</filter-name>
<filter-class>org.springframework.web.multipart.support.MultipartFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>multipartFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>