springboot錯誤頁面處理
結構如下:
在template資料夾下新建error資料夾
在error新建4xx.html檔案和5xx.html檔案
2. 新建hellocontroller 和 login.html
hellocontroller類
login.html頁面
3. 錯誤**
timestamp:時間戳
status:狀態碼
error:錯誤提示
exception:異常物件
message:異常訊息
errors: jsr303資料校驗的錯誤
5xx.html
4. 執行結果
SpringBoot定製錯誤頁面
1 有模板引擎的情況下,例如404錯誤,將會在thymeleaf的templates的error下尋找404.html,如果找不到再尋找4xx.html 所有4開頭的錯誤狀態碼如果找不到特定的html頁面將會指向4xx.html 頁面可以獲取到的資訊 timestamp 時間戳 status 狀態碼...
SpringBoot定製錯誤頁面和錯誤資料
直接丟擲異常,那麼瀏覽器是便會訪問錯誤頁面 public string error model model lang en charset utf 8 titletitle head 55555555555 5xx.html body html timestamp 時間戳 status 狀態碼 er...
SpringBoot定製錯誤的Json資料
1 自定義異常處理 返回定製json資料 1 controlleradvice 2public class myexceptionhandler 11 缺點 沒有自適應效果,只是會返回自定義的json資料 2 1 controlleradvice 2public class myexceptionh...