目录
Model
//返回界面
@RequestMapping("/getUiModel")
public String getUiModel(Model model) {
model.addAttribute("user", "麦克");
return "forward:welcome.jsp";
}
ModelMap
//返回界面
@RequestMapping("/getUiMap")
public String getUiMap(ModelMap map) {
map.put("user", "吉祥");
return "welcome";
}
ModelAttribute
访问:传入参数user,则会自动放入request域中 http://localhost:8080/getUiModelAttribute?user=abc
//返回界面
@RequestMapping("/getUiModelAttribute")
public String getUiModelAttribute(@ModelAttribute String user) {
return "welcome";
}
request.setAttribute(最原始的)
@RequestMapping("/getRequestDispatcher")
public void getRequestDispatcher(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setAttribute("user", "李四");
request.getRequestDispatcher("/WEB-INF/views/welcome.jsp").forward(request, response);
}
modelAndVIew.addObject
@RequestMapping("/getModelAndView")
public ModelAndView getModelAndView() {
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("paramName", "张三");
modelAndView.setViewName("welcome");
return modelAndView;
}