package com.controller; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestControllerAdvice; //全局捕獲異常 @RestControllerAdvice public class GlobalExceptionHandler { @ResponseBody @ExceptionHandler(value = Exception.class) public String handleException(Exception exception){ System.out.println("出現(xiàn)異常:"+exception); String result = "{code:500,msg:'"+exception+"'}"; return result; } } |
|
來(lái)自: 修行的嘟嘟 > 《軟件開發(fā)》