1. 程式人生 > >SpringBoot項目中,異常攔截

SpringBoot項目中,異常攔截

pan red exc 項目 登錄 redirect pub 異常處理 col

SpringBoot自帶異常攔截@ControllerAdvice

1.創建一個SellerExceptionHandler類打上@ControllerAdvice標簽

@ControllerAdvice
public class SellExceptionHandler {
}

2.創建異常處理程序@ExceptionHandler(value = SellerAuthorizeException.class)表示攔截的異常為SellerAuthorizeException異常

    /**
     * 攔截登錄異常
     * @return
     */
    @ExceptionHandler(value 
= SellerAuthorizeException.class) public ModelAndView handlerAuthorizeException(){ return new ModelAndView("redirect:" + projectUrlConfig.getSell() + "/sell/seller/toLogin"); }

SpringBoot項目中,異常攔截