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

posted @ 2020-12-08 17:06  dcrenl  阅读(152)  评论(0编辑  收藏  举报