postman测试传参格式
- 创建User实体
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class User {
private Integer id;
private String name;
}
- 接口参数是集合
@PostMapping("/test1")
public String test1(@RequestBody List<User> userList) {
return "SUCCESS";
}
postman传参形式:
[
{
"id": 1,
"name": "ff"
},
{
"id": 2,
"name": "dfu"
}
]
测试结果:
- bean实体传参
①创建DTO,封装List集合
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserDTO {
private List<User> userList;
}
②参数传DTO
@PostMapping("/test2")
public String test2(@RequestBody UserDTO userDTO) {
return "userDTO SUCCESS";
}
③JSON传参形式
{
"userList": [
{
"id": 1,
"name": "ff"
},
{
"id": 2,
"name": "dfu"
}
]
}
④postman测试