正如muanis所提到的,自3.1spring以来,最好的方法是使用RedirectAttributes。我将i18n添加到博客中给出的示例中。因此,这将是一个完整的示例。
@RequestMapping("/users")@Controllerpublic class UsersController { @Autowired private MessageSource messageSource; @RequestMapping(method = RequestMethod.POST, produces = "text/html") public String create(@Valid User user, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest, Locale locale, RedirectAttributes redirectAttributes) { ... ... redirectAttributes.addFlashAttribute("SUCCESS_MESSAGE", messageSource.getMessage("label_user_saved_successfully", new String[] {user.getUserId()}, locale)); return "redirect:/users/" + enpreUrlPathSegment("" + user.getId(), httpServletRequest); } ... ...}
在您的消息束中添加适当的消息,例如messages.properties。
label_user_saved_successfully=Successfully saved user: {0}
编辑您的jspx文件以使用相关属性
<c:if test="${SUCCESS_MESSAGE != null}"> <div id="status_message">${SUCCESS_MESSAGE}</div></c:if>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)