@ExceptionHandler(value = Exception.class)

demo

@RestControllerAdvice
public class MyControllerAdvice {

        @ExceptionHandler(value = Exception.class)
        public String exception(){
            return "error";
        }

}
@RequestMapping("/getUser")
    public User getUser(Long id){
        int i = 1/0;
        return userService.getUser(id);
    }

你可能感兴趣的:(springboot,java,jvm,servlet)