6.Spring MVC @RequestParam

在index.jsp中加

TestRequestParam

HelloController

 //测试@RequestParam
  @RequestMapping(value = "/testRequestParam")
  public String testRequestParam(@RequestParam(value = "username") String username, @RequestParam(value = "age", required = false, defaultValue = "0") Integer age) {
    System.out.printf("testParam, username: " + username + ", age: " +age);
    return "Hello";
  }

@RequestParam来映射请求参数
value 值即请求参数的参数名
required 该参数是否必须,默认为true
defaultValue 请求参数的默认值


源码:https://github.com/gurongkang/TestSpringMVC.git tag:5

你可能感兴趣的:(6.Spring MVC @RequestParam)