2017-03-03 23 views
1

我有一個Spring控制器,它將重定向返回給另一個控制器。如何傳遞兩個Spring控制器內的參數

首先是這樣的

@RequestMapping(value = "/some-url", method = 
{ RequestMethod.POST, RequestMethod.GET }) 
public String test(final Model model) 
{ 
    ... 
    return "redirect:http://someurl/checkout/response"; 
} 

二是掛鉤第一個控制器的號召,所以它看起來是這樣的:

@RequestMapping("/**/response") 
public String handleResponse(@RequestParam final MultiValueMap<String, String> params, @Valid @ModelAttribute final Cyber cyber, 
     final BindingResult bindingResult, final Model model, final HttpSession session, final HttpServletRequest request) throws CMSItemNotFoundException... 

我想知道如何通過「@RequestedParam PARAMS」並將Cyber​​對象從第一個控制器移動到第二個控制器。

回答

0

您可以使用@SessionAttributes並將模型發送到其他內容。

更多click here

1

如果你還想要這些屬性來他們那裏消費後自動從會話刪除,您也可以使用FlashAttributes。爲此,您必須在方法handleResponse中聲明RedirectAttributes參數,並在其上調用addFlashAttribute。例如addFlashAttribute("cyber", cyber)。這些將作爲目標控制器中的模型屬性提供,並將自動退出會話。

相關問題