@RequestParam和@RequestBody区别
1. @RequestParam 用来处理Content-Type为application/x-www-form-urlencoded(默认类型如果不指定)
GET和POST请求传的参数会自动转换赋值到@RequestParam 所注解的变量上
例1: http://localhost:8080/test?name=zhangsan&age=30
@RequestMapping("/test") public String test(@RequestParam Map<String,String> param){ param.forEach((key,value)->{ System.out.println("key="+key+",value="+value); }); }
如上打印结果为:
key=name,value=zhangsan
key=age,value=30
例2: http://localhost:8080/test?name=zhangsan
@RequestMapping("/test") public String test(@RequestParam String name){ System.out.println("name="+zhangsan); }
如上打印结果为:
name=zhangsan