• 数据显示到前端


    第一种 : 通过ModelAndView

     1 public class ControllerTest1 implements Controller {
     2 
     3    public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
     4        //返回一个模型视图对象
     5        ModelAndView mv = new ModelAndView();
     6        mv.addObject("msg","Tst");
     7        mv.setViewName("test");
     8        return mv;
     9   }
    10 }

    第二种 : 通过Model

     1   @RequestMapping(path = "/u1")
     2     public String setName(@RequestParam("userName") String name, Model model){
     3         model.addAttribute("hello",name);
     4 
     5         return "Login";
     6     }
     7     /**
     8      * 接收前端用户传递的参数,判断参数的名字,假设名字直接在方法上,可以直接使用
     9      * 假设传递的是一个对象User,匹配User对象中的字段,如果名字一致就能匹配,要是不一样则为null
    10      *
    11      * @param student
    12      * @param model
    13      * @return
    14      */
    15     @RequestMapping(path = "/u2")
    16     public String setName2(Student student, Model model){
    17         model.addAttribute("student",student);//student传到前端的数据
    18     //返回映射地址
    19         return "Login";
    20     }

    第三中:通过ModelMap

    1     @RequestMapping(path = "/u3")
    2     public String setName3(Student student,ModelMap modelMap){
    3         //"student"传到前端的数据
    4         modelMap.addAttribute("student",student);
    5         //返回映射地址
    6         return "Login";
    7     }
  • 相关阅读:
    HDU 1175 连连看 (DFS+剪枝)
    CF702F T-Shirts
    UVA12538 Version Controlled IDE
    P2605 [ZJOI2010]基站选址
    P3835 【模板】可持久化平衡树
    CF915E Physical Education Lessons
    P3701 「伪模板」主席树
    P1198 [JSOI2008]最大数
    P3466 [POI2008]KLO-Building blocks
    P3919 【模板】可持久化数组(可持久化线段树/平衡树)
  • 原文地址:https://www.cnblogs.com/rzkwz/p/12678623.html
Copyright © 2020-2023  润新知