Spring MVC 传值(一)
1. 从视图传值给Controller
Internal View Resolver 方法, 通过函数的参数来传递。在HelloController.java文件中,
-----------
@RequestMapping({"/hello"})
public String hello(String stringIn){ //此时在浏览器中输入 {url}/hello?stringIn=AAA
System.out.println(stringIn);
return "hello";
}
==========
可见,有 public String hello(String stringIn) ,通过函数参数传值给Controller的方法。
这里介绍使用@RequestParam来传值给Controller。
在src/main/java/.../HomeController.java中
@RequestMapping({"/view2controller"}) // ?inString=AAA,通过这种方式传值