1. 404
    /**
     * 描述:统一处理404异常
     *
     * @outhor ios
     * @create 2019-01-04 3:49 PM
     */
    @Controller
    public class NotFoundException implements ErrorController {
    
        @Override
        public String getErrorPath() {
            return "/error";
        }
    
        @RequestMapping("/error")
        public String error(ModelMap map){
            map.addAttribute("message", "404 not found link!");
            return "uploadStatus";
        }
    
    }
    

     

  2. 500
    /**
     * 描述: 统一处理服务器500异常
     *
     * @outhor ios
     * @create 2019-01-04 3:01 PM
     */
    @ControllerAdvice
    public class GloadExceptionController {
    
        @ExceptionHandler(Exception.class)
        public String exceptionHandler(Exception e, RedirectAttributes attributes){
            System.out.println(e.getClass().getName());
            attributes.addFlashAttribute("message", "error : " + e.getCause().getMessage());
            return "redirect:/uploadStatus";
        }
    
    }
    

     

相关文章:

  • 2021-06-08
  • 2021-05-22
  • 2021-10-02
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-13
  • 2021-07-15
  • 2021-05-21
  • 2021-04-13
  • 2021-08-18
相关资源
相似解决方案