ModelAndView
@RequestMapping(path = "/teacher", method = RequestMethod.GET)
public ModelAndView getTeacher() {
ModelAndView mav = new ModelAndView();
mav.addObject("name", "张三");
mav.addObject("age", 30);
mav.setViewName("/demo/view");
return mav;
}
Model(常用):model的数据从前端传过来(比如同名传输等,这也解释了当初疑惑的一个问题:Controller层的数据从哪来?)
@RequestMapping(path = "/school", method = RequestMethod.GET)
public String getSchool(Model model) {
model.addAttribute("name", "北京大学");
model.addAttribute("age", 80);
return "/demo/view";
}