在POST方法的RequestMapping中映射List<Item>,可以使用@RequestParam注解来获取请求参数,并将参数值映射到List<Item>对象中。
具体步骤如下:
@PostMapping("/items")
public void createItems(@RequestParam List<Item> items) {
// 处理items数据
}
@PostMapping("/items")
public void createItems(@RequestParam("items") List<Item> items) {
// 处理items数据
}
public class Item {
private String name;
private int quantity;
// 省略getter和setter方法
}
这样,在发送POST请求时,可以将Item对象的数据以JSON格式传递给服务器。例如,使用Postman工具发送以下请求:
URL: http://localhost:8080/items Method: POST Body:
[
{
"name": "item1",
"quantity": 10
},
{
"name": "item2",
"quantity": 5
}
]
服务器端的Controller方法将会接收到List<Item>对象,可以对其进行进一步处理。
关于腾讯云相关产品和产品介绍链接地址,可以参考腾讯云官方文档或者腾讯云官网的相关页面。