Performing a redirect from a spring MVC @ExceptionHandler method

后端 未结 4 821
心在旅途
心在旅途 2021-02-07 10:49

I want to have the following method:

@ExceptionHandler(MyRuntimeException.class)
public String myRuntimeException(MyRuntimeException e, RedirectAttributes redire         


        
4条回答
  •  难免孤独
    2021-02-07 10:59

    Since Spring 4.3.5 (SPR-14651) you can use stright away your first aproach:

    @ExceptionHandler(MyRuntimeException.class)
    public String myRuntimeException(MyRuntimeException e, RedirectAttributes redirectAttrs){
        redirectAttrs.addFlashAttribute("error", e);
        return "redirect:someView";
    }
    

提交回复
热议问题