第一种:
@Controller
public class Test{
@Resource
private SelctService selectService;
@RequestMapping("/test/select")
public ModelAndView passValue(String id){
ModelAndView mav =new ModelAndView();
User user=selectService.queryById(id);
mav.addObject("user",user);
mav.setViewName("index");
return mav;
}
}
第二种:
@Controller
public class Test{
@Resource
private SelctService selectService;
@RequestMapping("/test/select")
public ModelAndView passValue(String id){
Map<String,Object> map = new hashMap<String,Object>;
User user=selectService.queryById(id);
map.put("user",user);
return forword("index", map);
}
}
第三种:
@Controller
public class Test{
@Resource
private SelctService selectService;
@RequestMapping("/test/select")
public ModelAndView passValue(String id){
Map<String,Object> data = new hashMap<String,Object>;
User user=selectService.queryById(id);
data.put("user",user);
return new ModelAndView("index",data);
}
}
第四种://这种属于返回String,仅有ModelAndMap
@Controller
public class Test{
@Resource
private SelctService selectService;
@RequestMapping("/test/select")
public String passValue(String id,ModelMap moap){
Map<String,Object> data = new hashMap<String,Object>;
User user=selectService.queryById(id);
moap.put("user",user);//或者moap.addAtribute("user",user);
return "index";
}
}
第五种:
public ModelAndView login(){
RedirectView view = new RedirectView("regirst.do");
return new ModelAndView(view);
}