Spring mvc springmvc中的多个flash消息
在Spring MVC 3.1中,我可以做到:Spring mvc springmvc中的多个flash消息,spring-mvc,Spring Mvc,在Spring MVC 3.1中,我可以做到: @RequestMapping(value = "{id}/edit", method = RequestMethod.POST) public String update(Category category, @PathVariable Integer id, @RequestParam("childrenOrder") int[] childrenOrder, RedirectAttributes redirectAttrib
@RequestMapping(value = "{id}/edit", method = RequestMethod.POST)
public String update(Category category, @PathVariable Integer id,
@RequestParam("childrenOrder") int[] childrenOrder,
RedirectAttributes redirectAttributes) {
if (!id.equals(category.getCategoryId())) throw new IllegalArgumentException("Attempting to update the wrong category");
categoryMapper.updateByPrimaryKey(category);
redirectAttributes.addFlashAttribute("flashSuccessMsg", "Update Successful"); //ADD FLASH MESSAGE
return "redirect:/admin/categories.html";
}
然后在视图中显示flash消息:
<p>${flashSuccessMsg}</p>
${flashsuccesssg}
但是我更希望有一个flash消息列表,然后在视图中迭代
这可能吗
如果我这样做:redirectAttributes.addFlashAttribute(“更新成功”)代码>
i、 e.我不给flash消息命名,如何在视图中检索它?您尝试过使用吗
这是一个解决方案,但可能有多个方法调用addFlashAttribute。我希望不必用列表手动操作。@马克,你能帮我知道还有什么其他方法吗?
@RequestMapping(value = "{id}/edit", method = RequestMethod.POST)
public String update(Category category, @PathVariable Integer id, @RequestParam("childrenOrder") int[] childrenOrder, RedirectAttributes redirectAttributes) {
if (!id.equals(category.getCategoryId())) throw new IllegalArgumentException("Attempting to update the wrong category");
categoryMapper.updateByPrimaryKey(category);
List<String> messages = new ArrayList<String>();
// populate messages
redirectAttributes.addFlashAttribute("messages", messages);
return "redirect:/admin/categories.html";
}
<c:foreach items="${messages}">
...
</c:foreach>