一、ModelAndView
@RequestMapping("/selectById")
public ModelAndView queryById(Integer id){
ModelAndView modelAndView = new ModelAndView();
//设置视图名字(jsp路径)
modelAndView.setViewName("selectById");
//设置数据
List<Student> queryList = studentService.getById(id);
//相当于
modelAndView.addObject("list",queryList);
return modelAndView;
}
二、String
- 传入一个model对象负责数据部分
- 视图部分直接写在return后面
@RequestMapping("/selectById")
public String queryById(Integer id,Model model){
// Model model 或者ModelMap modelMap都可以
//设置数据
List<Student> queryList = studentService.getById(id);
model.addAttribute("list",queryList);
return "selectById";
}
三、void
自己书写响应代码