使用@RequestParam可以将URL中的请求参数,绑定到方法的入参上,并通过@RequestParam的3个参数进行配置
| Modifier and Type | Optional Element | Description |
| String | defaultValue | 方法入参默认值 |
| boolean | required | 是否必须包含该参数,默认为true |
| String | value | 请求参数名 |
其实不使用@RequestParam,SpringMVC也会将request的parameter自动绑定到method的parameter中,
使用@RequestParam只不过是对parametr进行配置,和对URL更精确化的配置
代码:
)2: @Controllerclass TestRequestParam {;5:/** 使用@RequestParam绑定入参,并进行配置** 当请求为:testRequestParam/user?name=zs&age=200时* 输出结果:name = zs class = j1001 age = 200** 当请求为:testRequestParam/user?name=zs&age=200&class=j111时* 输出结果:name = zs class = j111 age = 200* */)) String name,) String cla,18: Integer age) {+ age);return SUCCESS;21: }22: }