How to pass model attributes from one Spring MVC controller to another controller?

后端 未结 10 1331
暗喜
暗喜 2020-11-27 13:19

I am redirecting from a controller to another controller. But I also need to pass model attributes to the second controller.

I don\'t want to put the model in sessi

10条回答
  •  迷失自我
    2020-11-27 13:48

    If you want just pass all attributes to redirect...

    public String yourMethod( ...., HttpServletRequest request, RedirectAttributes redirectAttributes) {
        if(shouldIRedirect()) {
            redirectAttributes.addAllAttributes(request.getParameterMap());
            return "redirect:/newPage.html";
        }
    }
    

提交回复
热议问题