我在我的應用程序中使用彈簧安全性。RediectAttributes不能與彈簧安全工作
在我的控制器方法之一,我重定向到另一個控制器方法和附加模型屬性,但我沒有在下一個控制器方法中獲得這些modelAttributes。
是否因爲Spring Security Filter的內部重定向而發生這種情況,這可能會導致重定向閃存屬性被破壞?
這是我的代碼:
@RequestMapping("/method1")
public String firstMethod(Model model,RedirectAttributes redirectAttributes) {
... do something ...
redirectAttributes.addFlashAttributes("message","This is a test message");
return "redirect:/method2";
}
@RequestMapping("/method2")
public String secondMethod(@ModelAttribute("message") String message, Model model) {
... do something ...
return "some_view";
}
在這裏,在secondMethod消息來了爲空白( 「」);
嘗試使用'model.addAttribute()'相反 –
model.addAttribute不會生存重定向 – Pankaj