Springboot 全局统一处理异常
import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; /** * @author dcrenl: 2020-10-12 19:47:39 */ @ControllerAdvice public class GlobalExceptionHandler { @ResponseBody @ExceptionHandler(Exception.class) public String globalException(Exception ex) { return ex.getMessage(); } }
本文参考:https://www.cnblogs.com/magicalSam/p/7198420.html
赞 (0)