版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
首先我们在Controller中写这样一个方法
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/sesameSelfMentionPoint")
public class SesameSelfMentionPointController {
@PostMapping("/test")
public List<String> test(@RequestBody List<String> list) {
for (String s : list) {
System.out.println(s);
}
return list;
}
}
启动项目访问接口需要这样传参
- 首先需要对应post请求
- 在Headers中加入Content-Type,application/json
- 在body中选择raw后再选择json,并填入中括号加字段名
- 点send按钮即可成功访问接口,结果如下
[
"a",
"b",
"c"
]
此致,用postman测试List集合的接口结束了,欢迎大家关注留言,感谢!