1.拼接字符串:return "redirect:/page/second?param1=lay¶m2=lay2";
2.采用RedirectAttribute来传参数:
public String first(RedirectAttribute redirectAttribute){
redirectAttribute.addAttribute("param1", "lay");
return "redirect:/page/second";
}
3.RedirectAttribute—–addFlashAttribute()的用法:
@Controller
@RequestMapping("/page")
public class redirectDemo{
@RequestMapping("/first")
public String first(RedirectAttribute redirectAttribute){
redirectAttribute.addFlashAttibute("param1", "lay");
return "redirect:/page/second";
}
@RequestMapping("/second")
public String second(@ModelAttribute("param1") String param1){
System.out.println(param1);
return "second";
}
}
时间: 2024-12-19 22:01:16