使用DispatcherServlet
@Configuration
public class WebConfig {
@Bean
public ServletRegistrationBean apiV1ServletBean(WebApplicationContext wac) {
DispatcherServlet ds = new DispatcherServlet(wac);
ServletRegistrationBean bean = new ServletRegistrationBean(ds, "/*");
bean.setName("xxx");
bean.addUrlMappings("/xxx/*");
return bean;
}
}
MultipartFile接收不到文件
@RequestMapping(method = RequestMethod.POST)
public Response<String> site(@RequestParam("file") MultipartFile file, String userId, HttpServletRequest request) {
}
错误报告:Required request part 'file' is not present
Make sure the parameter name "file" is correct?
Try this, this is how I use it, no problem.
Plus front-end
I just encountered this problem today, and I solved it after research.
This is because the configuration of the ServletRegistrationBean injected by yourself is different from the ServletRegistrationBean injected by spring boot by default. The ServletRegistrationBean you injected yourself is not configured to handle upload requests by default.
Please refer to the following configuration: