使用@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: @Controller
class 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: }

相关文章:

  • 2021-05-25
  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
  • 2022-12-23
  • 2022-12-23
  • 2021-08-12
猜你喜欢
  • 2021-07-02
  • 2021-06-30
  • 2022-03-04
  • 2022-12-23
  • 2022-12-23
  • 2021-05-10
  • 2021-06-10
相关资源
相似解决方案