val mvcResultImage = this.mockMvc!!.perform(MockMvcRequestBuilders.multipart("/somepath)
.file("files[]", imageFile.getBytes())
.characterEncoding("UTF-8"))
.andReturn()
在一个具有功能的控制器的集成测试中
@PostMapping(path = ["/somepath"],
consumes = [MediaType.MULTIPART_FORM_DATA_VALUE],
produces = [MediaType.APPLICATION_JSON_VALUE])
@ResponseBody
fun createFromBytes(@RequestParam("files[]") file: MultipartFile): ResponseEntity<Any> {
...
}
在2.3中,我能够在控制器函数中处理请求,而在2.4中,控制器函数会引发
org.springframework.web.multipart.support.MissingServletRequestPartException
带着信息
Required request part 'files[]' is not present
我在迁移指南和此版本更改的已处理问题列表中找不到任何内容。
重命名为
file
在这两个控制器和请求没有帮助,我不记得为什么我添加了
[]
我通过maven父机制使用springboot
spring-boot-starter-parent:2.4.1
.