Spring boot 全局捕获异常

2019-10-25  本文已影响0人  不务正业的程序猿

@RestControllerAdvice(basePackages ="xx.xxx")

public class GlobalExceptionHandlerextends ResponseEntityExceptionHandler {

private static final Loglogger = LogFactory.getLog(GlobalExceptionHandler.class);

    @ExceptionHandler(value = Exception.class)

public ResulterrorHandler(Exception ex) {

String msg;

        msg = ex.getMessage();

        if (msg ==null || msg.length() ==0) {

msg ="xxxxxxx";

        }

ex.printStackTrace();

        return Result.error(msg);

    }

}

上一篇 下一篇

猜你喜欢

热点阅读