1. request param(query param): 请求参数
????????用对象接收或声明参数接收都可以
????????在postman中,用params带参
示例:
@PostMapping("t1")
public Object test1(String userName, User user){
System.out.println("userName : " + userName);
System.out.println("user : " + user);
return user;
}
2. form data: 表单参数
????????用对象接收或声明参数接收都可以
????????在postman中,用body-->form-data带参
示例:
@PostMapping("t2")
public Object test2(User user){
System.out.println("user : " + user);
return user;
}
3. path param: 路径参数.
????????可以用对象接收也可以声明属性接收, @PathVariable("参数名")
????????在postman中,在路径后面挂上 /参数值
示例:
@PostMapping("t3/{userName}/{password}")
public Object test3(User user, @PathVariable("userName") String userName){
System.out.println("userName : " + userName);
System.out.println("user : " + user);
return user;
}
4. body: json对象.
????????一般用实体接收,@RequestBody 实体对象, 或者 @RequestParam("参数名")
????????在postman中,用body-->row-->用键值对方式传参{"属性":"值"}
* 注:@RequestBody和@RequestParam 默认要求所有属性接收的值不能为空,如果没接收到值会报错
* 如果允许接收空值,需要设置 @RequestBody(required = false),@RequestParam注解同理
示例:
@PostMapping("t4")
public Object test4(@RequestBody(required = false) User user){
// System.out.println("userName : " + userName);
System.out.println("user : " + user);
return user;
}
|