ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
**1.ModelAndView** ~~~ @RequestMapping("fun9") public ModelAndView fun9(ModelAndView modelAndView){ modelAndView.addObject("name","tom"); modelAndView.setViewName("/demo1"); return modelAndView; } ~~~ 视图获取变量 ~~~ <h1>hello ${requestScope.name}</h1> ~~~ **2.其他方式传值** ~~~ //Request作用域 @RequestMapping("fun9") public String fun9(ModelAndView modelAndView, Model model, ModelMap modelMap, Map map,HttpServletRequest request){ modelAndView.addObject("name","tom"); //方式1 model.addAttribute("age",18); //方式2 modelMap.addAttribute("sex","男"); //方式三 map.put("card", "112233"); //方式四 request.setAttribute("birthday","1998-05-20");//方式5 return "/demo1"; } ~~~ ~~~ <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> <h1>hello springMVC!!!!</h1> <h1>hello ${requestScope.name}</h1> <h1>age: ${requestScope.age}</h1> <h1>sex: ${requestScope.sex}</h1> <h1>card: ${requestScope.card}</h1> <h1>birthday: ${requestScope.birthday}</h1> </body> </body> </html> ~~~