通过 url模板进行
@RequestMapping("/login")
public String login(Model model){
model.addAttribute("path", "index.html");
return "redirect:/app/{path}";
}
url: /app/index.html
@RequestMapping("/login")
public String login(Model model){
model.addAttribute("path", "index.html");
model.addAttribute("userId", "5646");
return "redirect:/app/{path}";
}
url: /app/index.html?userId=5646
使用 url 模板,spring 会将变量中所有不安全字符都会进行转义
使用 flash 属性
@RequestMapping("/login")
public String login(RedirectAttributes model){
model.addAttribute("path", "index.html");
model.addFlashAttribute("user", new SysUser());
return "redirect:/app/{path}";
}
我们使用 flashAttribue 传递一个对象