一、 @exceptionhandler
處理程式
@exceptionhandler(value=arithmeticexception.class)
public string resolveexception(exception e )
@exceptionhandler(value=runtimeexception.class)
public string resolveruntimeexception(exception e )
@exceptionhandler(value=exception.class)
public string testresolveexception(exception e )
如果都在的話,異常會選擇最近的去處理
只可以用在本類
二、@controlleradvice
如果本類中沒有@exceptionhandler 會去@controlleradvice中的exceptionhandler註解方法
@controlleradvice //如果當前類handler沒有處理異常的方法,那麼久會去標註@controlleradvice類裡去找
public class resolveexceptionclass
}三、顯示異常資訊在頁面
異常資訊顯示,必須設定返回值為modelandview 不可以方在map裡邊
@exceptionhandler(value=arithmeticexception.class)
public modelandview resolveexception(exception e )
四@responsestatus使用
@responsestatus(value=httpstatus.unauthorized,reason="寶貝,你還沒有長大")
public class unauthorizedexception extends runtimeexception {
/***
*/private static final long serialversionuid = 1l;
具體異常配置具體的頁面
spring mvc 異常處理
一般來說,程式每出現乙個異常就需要throws 或者try catch語句塊進行處理,這樣處理異常的方法比較少的情況,還體現不出麻煩,如果需要處理異常的方法比較多的情況下,有乙個統一處理異常方法就顯得尤其重要,即所有丟擲的異常都在乙個方法進行處理,這樣可以集中 簡便,如果需要修改異常處理的方式也比較...
springmvc異常處理
1.異常處理思路 系統中異常包括兩類 預期異常和執行時異常runtimeexception,前者通過捕獲異常從而獲取異常資訊,後者主要通過規範 開發 測試的手段減少執行時異常的發生。系統的dao service controller出現異常都通過throws exception向上丟擲,最後由spr...
SpringMVC異常處理
一 springmvc異常處理流程 預期異常,執行時異常 runtimeexception 前者通過捕獲異常從而獲取異常資訊,後者主要通過規範 開發 測試通過手段減少執行異常的發生。系統的dao service controller 出現都通過throw cetion向上跑出,最後由springmv...