首先我们在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集合的接口结束了,欢迎大家关注留言,感谢!
来源:51CTO
作者:qq:953692539
链接:https://blog.csdn.net/m0_37562069/article/details/102743452