备案成功后怎么建设网站,包头网站建设制作,sem对seo的影响有哪些,wordpress安装手机版文章目录 目录1、springmvc使用ServletAPI向request作用域共享数据#xff08;原生态#xff09;2、springmvc使用ModelAndView向request作用域共享数据3、springmvc使用Model向request作用域共享数据4、springmvc使用map向request作用域共享数据5、springmvc使用ModelMap向r… 文章目录 目录1、springmvc使用ServletAPI向request作用域共享数据原生态2、springmvc使用ModelAndView向request作用域共享数据3、springmvc使用Model向request作用域共享数据4、springmvc使用map向request作用域共享数据5、springmvc使用ModelMap向request作用域共享数据 目录
1、springmvc使用ServletAPI向request作用域共享数据原生态
前端请求
a th:href{/test}request作用域共享数据/a后台ServletAPI向request作用域共享数据 RequestMapping(/test)public String testRequestByServletAPI(HttpServletRequest request) {//想request作用域中共享数据存数据request.setAttribute(testrequest, servletapi);return succeed;//request作用域中存数据转发到相应的页面进行取值}页面取值
p th:text${testrequest}/p2、springmvc使用ModelAndView向request作用域共享数据
前端请求
a th:href{/testModelAndView}使用ModelAndView向request作用域共享数据/a后端使用ModelAndView向request作用域共享数据
RequestMapping(/testModelAndView)//使用ModelAndView时返回的方法类型必须是ModelAndViewpublic ModelAndView testModelAndView() {//创建ModelAndView对象ModelAndView mav new ModelAndView();//使用ModelAndView共享数据ModelAndView有两个作用//Model处理模型数据向request作用域中共享数据将底层获取的数据进行存储或者封装//最后将数据传递给Viewmav.addObject(ModelAndView, hello,ModelAndView);//View视图设置视图名称:设置转向地址mav.setViewName(succeed);return mav;}页面取值
p th:text${ModelAndView}/p总结 1、使用ModelAndView向request作用域中共享数据时。方法的返回值必须是ModelAndView。 2、ModelAndViewModel‘模型’进行数据的存储和封装跳转到View中 3、View视图设置跳转的视图 3、springmvc使用Model向request作用域共享数据
前端
a th:href{/testModel}使用Model向request作用域中共享数据/a后台使用Model进行数据共享存储数据:
RequestMapping(/testModel)public String tsetModel(Model model){//形参的位置创建Model//使用Model向erquest中存储数据model.addAttribute(tsetModel,hello,model);return succeed;}取值
h1 th:text${tsetModel}/h1总结
1、在方法形参的位置中创建Model对象进行数据的存储 4、springmvc使用map向request作用域共享数据
前端请求
a th:href{/testmap}使用map向request作用域共享数据/a后端存储数据 RequestMapping(/testmap)public String testmap(MapString,Object map) {map.put(map, hellq,map);return succeed;}取值
h1 th:text${map}/h1总结 1、方法形参的位置中创建MapString,Object map 5、springmvc使用ModelMap向request作用域共享数据
前端请求
a th:href{/testmodelmap}使用ModelMap向request作用域共享数据/a使用ModelMap向request作用域中存储数据
RequestMapping(/testmodelmap)public String testmodelmap(ModelMap modelMap) {modelMap.addAttribute(modelmap,hello,ModelMap);return succeed;}取值 根据键值对取值
h1 th:text${modelmap}/h1