如何限制利用spring boot 框架自动限制上传文件

spring:
  application:
    name: appname
  servlet:
    multipart:
      enabled: true
      max-file-size: 512MB
      max-request-size: 512MB

@ExceptionHandler
public String handleMaxUploadSizeExceededException(MaxUploadSizeExceededException ex, NativeWebRequest request) {
if(ex instanceof org.springframework.web.multipart.MaxUploadSizeExceededException){
//    request.setAttribute("error", "文件超过长度");
request.setAttribute("error", "文件超过长度",112233);
}
return "";
}

 

posted @ 2020-05-30 14:12  奥兰王子  阅读(378)  评论(0编辑  收藏  举报