1.ModelAndView
@Controller
public class HelloController {
@RequestMapping("hell")//http://localhost:8080/hell.do
public ModelAndView hello(){
ModelAndView mv=new ModelAndView();
/*
模型数据:Model
视图:View
*/
//(值名字,传递的值)
mv.addObject("hello","Hello SpringMVC");
//jsp页面名字
mv.setViewName("hello");
return mv;
}
}
2.其他方法
/**
* 设置域对象属性
* 1.ModelAndView
* 2.ModelMap
* 3.Model
* 4.Map
* 5,HttpServletRequest
*/
@Controller
public class ModelController {
@RequestMapping("m1")
public String fun1(HttpServletRequest request){
request.setAttribute("hello","hello fun1");
//返回视图名
return "hello";
}
@RequestMapping("m2")
public String fun2(ModelMap modelMap){
modelMap.addAttribute("hello","hello fun2");
//返回视图名
return "hello";
}
@RequestMapping("m3")
public String fun3(Model model){
model.addAttribute("hello","hello fun2");
//返回视图名
return "hello";
}
@RequestMapping("m4")
public String fun4(Map map){
map.put("hello","hello fun2");
//返回视图名
return "hello";
}
}
```JAVA
标签:传参,return,RequestMapping,对象,视图,public,ModelAndView,hello
From: https://www.cnblogs.com/lwx11111/p/16769802.html