SpringMvc跳转传值的三种方法
程序员文章站
2022-05-18 14:19:20
...
SpringMvc跳转传值的三种方法
1、使用ModelAndView
@RequestMapping("/test2")
public ModelAndView test2(ModelAndView modelAndView){
String name = "张三";
modelAndView.setViewName("conter/test");
modelAndView.addObject("name", name);
return modelAndView;
}
2.使用serlvet
@RequestMapping("/test")
public String test(HttpServletRequest request,HttpServletResponse response){
String name = "张三";
request.setAttribute("name",name);
return "/conter/test";
}
3.使用Model对象
@RequestMapping("/test2")
public ModelAndView test2(ModelAndView modelAndView){
String name = "张三";
modelAndView.setViewName("conter/test");
modelAndView.addObject("name", name);
return modelAndView;
}