Spring-MVC上传文件出现错误

一、问题描述

Resolving exception from handler [public java.lang.String com.online.education.opt.controller.CourseSectionController.doImport(java.lang.Long,org.springframework.web.multipart.MultipartFile)]: org.springframework.web.bind.MissingServletRequestParameterException: Required MultipartFile parameter 'courseSectionExcel' is not present
 [04/12 17:53] Resolving exception from handler [public java.lang.String com.online.education.opt.controller.CourseSectionController.doImport(java.lang.Long,org.springframework.web.multipart.MultipartFile)]: org.springframework.web.bind.MissingServletRequestParameterException: Required MultipartFile parameter 'courseSectionExcel' is not present
 [04/12 17:53] Resolving exception from handler [public java.lang.String com.online.education.opt.controller.CourseSectionController.doImport(java.lang.Long,org.springframework.web.multipart.MultipartFile)]: org.springframework.web.bind.MissingServletRequestParameterException: Required MultipartFile parameter 'courseSectionExcel' is not present
 [04/12 17:53] Null ModelAndView returned to DispatcherServlet with name 'app-servlet': assuming HandlerAdapter completed request handling
 [04/12 17:53] Cleaning up multipart file [file] with original filename [导入课程章节模板.xlsx], stored in memory
 [04/12 17:53] 

二、问题解决

1、

有的说 true改成false,但这是掩耳盗铃

public String doImport(Long courseId,
			@RequestParam(value = "courseSectionExcel", required = true) MultipartFile excelFile) {
}

2、name值与value值不同

<div class="layui-input-block">
		<input type="file"  name="file" id="courseSectionExcel" name="courseSectionExcel"  "fileChange();">
</div>

两个name去掉前面那个。

发布了59 篇原创文章 · 获赞 6 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_27009225/article/details/89249452
今日推荐