SpringMVC_共享数据
HttpServletRequest 共享数据
@RequestMapping("/html1") public String testServletAPI(HttpServletRequest request) { request.setAttribute("id", "1"); return "html2"; }
ModelAndView 共享数据
@RequestMapping("/html1") public ModelAndView testModelAndView() { ModelAndView mav = new ModelAndView(); mav.addObject("id", "1"); mav.setViewName("html2"); return mav; }
Model 共享数据
@RequestMapping("/html1") public String testModel(Model model) { model.addAttribute("id","1"); return "html2": }
Map 共享数据
@RequestMapping("/html1") public String testMap(Map<String, Object> map) { map.put("id","1"); return "html2"; }
ModelMap 共享数据
@RequestMapping("/html1") public String testModelMap(ModelMap modelmap) { modelMap.addAttribute("id", "1"); return "html2"; }
HttpSession session共享数据
@RequestMapping("/testSession") public String testSession(HttpSession session) { session.setAttribute("id","1"); return "html2"; }
HttpSession application共享数据
@RequestMapping("/html1") public String testApplication(HttpSession session) { ServeletContext application = session.getServletContext(); application.setAttribute("id","1"); return "html2"; }