spring boot 錯誤頁,檔案上傳,異常處理

2021-09-03 02:18:18 字數 1465 閱讀 6428

1.放在resources/static/error下

2.錯誤頁配置

}}3.檔案上傳

#指定上傳的資料夾

spring.servlet.multipart.location=e:/springboot

#設定單個檔案最大最小

spring.servlet.multipart.max-file-size=5mb

#限制所有檔案最大最小

spring.servlet.multipart.max-request-size=20mb

/*

*採用spring提供的上傳檔案的方法

*/public string springupload(part file) throws myexception

catch(exception e)

}

4.防止大檔案上傳,***

自定義異常類

​public class myexception extends exception

public myexception(string message)

}​

檔案過大拋出自定義異常

public class fileuploadinterceptor implements handlerinterceptor 

}return true;

}}

全域性異常處理(返回字串)

@restcontrolleradvice

public class globalexceptionhandler

}

或者頁面(友好方式)

@controlleradvice

public class globalexceptionhandler

}

spring boot 錯誤處理

一 錯誤的處理 方法一 spring boot 將所有的錯誤預設對映到 error,實現errorcontroller controller public class baseerrorcontroller implements errorcontroller public string error...

SpringBoot錯誤處理

我們來看看錯誤處理是如何註冊的 private static class errorpagecustomizer implements errorpageregistrar,ordered override public void registererrorpages errorpageregist...

springboot遇到的錯誤

1.訪問時404,1 當你沒有在配置檔案中配置專案名時直接 http localhost 8080 url直接進行訪問 2.使用mybatis generator生成時,找不到類 tk.mybatis 4.0.3 3.使用tk外掛程式時,使用autowried報錯 spring boot中 clou...