CommonException.java 608 B

123456789101112131415161718
  1. package com.sf.conroller;
  2. import org.springframework.web.bind.annotation.ControllerAdvice;
  3. import org.springframework.web.bind.annotation.ExceptionHandler;
  4. import org.springframework.web.servlet.ModelAndView;
  5. @ControllerAdvice
  6. public class CommonException {
  7. @ExceptionHandler(value = {Exception.class})
  8. public ModelAndView testException(Exception e){
  9. System.out.println("error--->"+e.getMessage());
  10. ModelAndView modelAndView = new ModelAndView();
  11. modelAndView.setViewName("error");
  12. modelAndView.addObject("msg",e.getMessage());
  13. return modelAndView;
  14. }
  15. }