zoukankan      html  css  js  c++  java
  • SpringMVC跨重定向请求传递数据

    (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     }
  • 相关阅读:
    如何入门深度学习
    机器学习之激活函数
    轻量化模型之SqueezeNet
    聚类算法之MeanShift
    目标检测之RefineDet
    语义分割之RefineNet
    数学基础之高斯核函数
    目标检测之人脸识别
    梯度下降算法及优化方法
    机器学习高阶训练营知识点一览
  • 原文地址:https://www.cnblogs.com/fanqisoft/p/10263091.html
Copyright © 2011-2022 走看看