1.使用ServletAPI向request域对象中共享数据
<a th:href="@{/testRequest}">通过servletAPI像request作用域共享数据源</a><br/>
@RequestMapping("/testRequest")
public String testRequest(HttpServletRequest request){
request.setAttribute("username","jack");
return "success";
}
2.使用ModelAndView向request域对象共享数据
<a th:href="@{/testModeAndView}">通过ModeAndView像request作用域共享数据源</a><br/>
@RequestMapping("/testModeAndView")
public ModelAndView testModeAndView(){
ModelAndView mav = new ModelAndView();
mav.addObject("username","hello,modeAndView");
mav.setViewName("success");
return mav;
}
3.使用Model向request域对象共享数据
@RequestMapping("/testModel")
public String testModel(Model model){
model.addAttribute("username","hello,model");
System.out.println(model.getClass().getName());
return "success";
}
4.使用map向request域对象共享数据
@RequestMapping("/testMap")
public String testMap(Map<String,Object> map){
map.put("username","hello,map");
System.out.println(map.getClass().getName());
return "success";
}
5.使用ModelMap向request域对象共享数据
@RequestMapping("/testModelMap")
public String testModelMap(ModelMap modelMap){
modelMap.addAttribute("username","hello,modelMap");
System.out.println(modelMap.getClass().getName());
return "success";
}
6.使用session向Session共享域中共享数据
@RequestMapping("/testSession")
public String testSession(HttpSession session){
session.setAttribute("username","hello,session");
return "success";
}