springmvc上传文件,没有MultipartFile参数名报错直接 500,The current request is not a multipart急
展示controller 代码
@RequestMapping(value = "/uploadTest",method={POST,GET})
@ResponseBody
public String uploadTest(@RequestParam(required=false,value="file")MultipartFile file,HttpServletRequest request,HttpServletResponse response) throws IOException{
if(file == null){
return "没有图片文件";
}
String fileName = file.getOriginalFilename();
String filePath = request.getSession().getServletContext().getRealPath("/")+"/upload/";
File file2 = new File(filePath, System.currentTimeMillis() + fileName);
if(!file2.getParentFile().exists()){
file2.getParentFile().mkdir();
}
if(!file2.exists()){
file2.createNewFile();
}
file.transferTo(file2);
String name = file2.getName();
return null;
}
前端请求时 有file字段名是不会报错了,但没有文件或图片字段就直接 500 了,不管怎么调试都解决不了啊,网上也搜了不少解决方案但都是不行的
org.springframework.web.multipart.MultipartException: The current request is not a multipart request
at org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.assertIsMultipartRequest(RequestParamMethodArgumentResolver.java:216)
at org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.resolveName(RequestParamMethodArgumentResolver.java:167)
at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:89)
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:77)
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:162)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:129)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:747)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:676)
相关推荐
SpringMVC跨服务器上传错误 – Request processing failed; nested exception is com.sun.jersey.api.client.Uniform
问题描述 HTTP Status 500 – Request processing failed; nested exception is com.sun.jersey.api.client.UniformInterfaceException: PUT http://localhost:8090/picServer/uploads/QQ截图20200220003029.png returned a response status of 400 Bad Request type Exception report message Request processing failed; nested
基于SSM框架的社区住户信息管理系统设计与实现
Java Web后台管理系统开发中,SSM(Spring+SpringMVC+MyBatis)作为经典框架组合,通过显式配置让开发者深入理解依赖注入、请求分发与数据持久化的底层原理。Spring负责对象管理与事务控制,SpringMVC以前端控制器模式解耦Web层,MyBatis则以半自动ORM方式灵活编写动态SQL,三者整合为多角色权限控制、分页查询、文件上传等复杂场景提供了稳定支撑。本文以社区住户信息管理为业务背景,从系统架构搭建、数据库设计到报修工单状态流转、短信记录落库,完整呈现一个可复现的Java
SpringMVC整合KindEditor上传文件的处理
NULL 博文链接:https://huhongyu.iteye.com/blog/1816790
SpringMVC注解@RequestParam方法原理解析
主要介绍了SpringMVC注解@RequestParam方法原理解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
java实现多图片上传功能
主要为大家详细介绍了java多图片同步上传功能的实现方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下


Eclipse
