用postman测试List集合的接口

匿名 (未验证) 提交于 2019-12-03 00:15:02

首先我们在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;     } } 

启动项目访问接口需要这样传参

  1. 首先需要对应post请求
  2. 在Headers中加入Content-Type,application/json
  3. 在body中选择raw后再选择json,并填入中括号加字段名
  4. 点send按钮即可成功访问接口,结果如下
[     "a",     "b",     "c" ] 

此致,用postman测试List集合的接口结束了,欢迎大家关注留言,感谢!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!