constroller exception unified handling class

constroller exception unified handling class

Insert picture description here
The result is the processing result that you want to return, and the purpose of the blog is to illustrate the use of @controllerAdvice extensions in conjunction with exception classes

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class BaseExceptionHander {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        return new Result();
    }
}

Guess you like

Origin blog.csdn.net/Guesshat/article/details/112424695