用postman测试List集合的接口

寵の児 提交于 2019-12-02 08:39:48

首先我们在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集合的接口结束了,欢迎大家关注留言,感谢!

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