Handling MultipartException with Spring Boot and display error page

后端 未结 1 414
青春惊慌失措
青春惊慌失措 2021-01-13 08:02

I have a very simple file upload set up with Spring Boot. I was wondering if there was an easy way to display an error page when the maximum file size is exceeded.

I

相关标签:
1条回答
  • 2021-01-13 08:25

    Multipart request parsing happens before a handler is selected and hence there is no @Controller and therefore no @ControllerAdvice to speak of yet. You can use an ErrorController (see http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-web-applications.html#boot-features-error-handling) for that.

    BTW you don't need @RequestParam. It's enough that the argument type is MultipartFile.

    0 讨论(0)
提交回复
热议问题