@EXCEPTIONHANDLER注解使用和@ControllerAdvice
转载:https://blog.csdn.net/ChineseSoftware/article/details/118413266
https://www.freesion.com/article/1756683508/

@Controller
public class UserController {@RequestMapping("/pagejump") public String pageJump(){ String str=null; str.length(); return "ok"; } //该注解的作用是根据不同的异常跳转到不同的试图 @ExceptionHandler(value = {java.lang.NullPointerException.class}) public ModelAndView nullpointException(Exception e){ ModelAndView mv=new ModelAndView(); //将异常信息添加到ModelAndView中 mv.addObject("error1",e.toString()); //出现异常跳转到名为error1的视图 mv.setViewName("error1"); return mv; }}


浙公网安备 33010602011771号