開発者ドキュメント

Spring @ExceptionHandlerとRedirectAttributes

Spring 4.3.5と5.0 M4以降、

@ExceptionHandler`メソッドで

RedirectAttributes`引数をサポートしています。

    @ExceptionHandler(MyCustomException.class)
    public String handleError1(MyCustomException e, RedirectAttributes redirectAttributes) {

        redirectAttributes.addFlashAttribute("message", "abcdefg");
        return "redirect:/viewName";

    }

    @ExceptionHandler(MultipartException.class)
    public String handleError2(MultipartException e, RedirectAttributes redirectAttributes) {

        redirectAttributes.addFlashAttribute("message", e.getCause().getMessage());
        return "redirect:/viewName";

    }


P.Sこのhttps://jira.spring.io/browse/SPR-14651[SPR-14651]

をお読みください

参考文献


  1. SPR-14651

  2. リンク://spring-mvc/spring-mvc-exceptionhandler-example/[Spring

@ExceptionHandler]


例外

リンク://タグ/例外ハンドラ/[例外
ハンドラ]リンク://タグ/リダイレクト/[リダイレクト]

モバイルバージョンを終了