(1)使用URL模板以路径变量和查询参数的形式传递数据(一些简单的数据)

 1     @GetMapping("/home/index")
 2     public String index(Model model){
 3         Meinv meinv = new Meinv("gaoxing",22);
 4         model.addAttribute("lastName",meinv.getLastName());
 5         model.addAttribute("age",meinv.getAge());
 6         return "redirect:/home/details/{lastName}";
 7     }
 8 
 9     @GetMapping("/home/details/{lastName}")
10     public String details(@PathVariable String lastName, @RequestParam Integer age){
11         System.out.println(lastName);
12         System.out.println(age);
13         return "home";
14     }

(2)通过flash属性发送数据(对象等复杂数据)

 1     @GetMapping("/home/index")
 2     public String index(RedirectAttributes model){
 3         Meinv meinv = new Meinv("gaoxing",22);
 4         model.addAttribute("lastName",meinv.getLastName());
 5         model.addFlashAttribute("meinv",meinv);
 6         return "redirect:/home/details/{lastName}";
 7     }
 8 
 9     @GetMapping("/home/details/{lastName}")
10     public String details(@PathVariable String lastName, Model model){
11         Meinv meinv = null;
12         if(model.containsAttribute("meinv")){
13             meinv = (Meinv) model.asMap().get("meinv");
14         }
15         System.out.println(meinv);
16         return "home";
17     }

 

相关文章:

  • 2021-06-19
  • 2022-12-23
  • 2021-09-22
  • 2021-09-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-25
  • 2022-12-23
  • 2019-12-14
  • 2021-07-26
  • 2021-06-15
  • 2022-12-23
  • 2021-06-06
相关资源
相似解决方案