Springboot統一異常處理(@ControllerAdvice)
阿新 • • 發佈:2019-05-17
except ota frame spa esp 攔截 web 調用接口 sta
1 import org.springframework.web.bind.annotation.ControllerAdvice; 2 import org.springframework.web.bind.annotation.ExceptionHandler; 3 import org.springframework.web.bind.annotation.ResponseBody; 4 import org.springframework.web.bind.annotation.ResponseStatus; 5 6 import javax.servlet.http.HttpServletRequest;7 import java.util.*; 8 9 /** 10 * 統一異常攔截處理器 11 */ 12 @ControllerAdvice 13 public class AppExceptionHandler { 14 15 @ExceptionHandler(Exception.class) 16 @ResponseBody 17 @ResponseStatus 18 public String handlerError(HttpServletRequest req, Exception e) { 19 String result = "";20 result = "調用接口失敗,請聯系管理員"; 21 return result; 22 } 23 }
Springboot統一異常處理(@ControllerAdvice)