1. 使用 redirect 进行页面跳转时参数的传递
★ 使用的API: RedirectAttributes , Model 的加强子接口
public interface RedirectAttributes extends Model
★ 方法 :
RedirectAttribute addFlashAttribute () ; //直接就可以在跳转的页面用 el 表达式获取
RedirectAttribute addAttribute() ; // 会在跳转的链接尾端拼 参数★ i . e :
//controller 中 方法
@RequestMapping(value = "/accounts",method = RequestMethod.POST)
public String handle(Account account, RedirectAttributes redirectAttributes){
redirectAttributes.addAttribute("id",account.getId).addFlashAttribute("message", "Account created!");
return "redirect:/accounts/{id}";
}
本文介绍了如何在Spring MVC中使用RedirectAttributes接口进行页面跳转并传递参数的方法。包括使用addAttribute方法在URL中直接拼接参数,以及使用addFlashAttribute方法将数据暂存以便在重定向的目标页面通过EL表达式获取。

4088

被折叠的 条评论
为什么被折叠?



