用postman测试List集合的接口

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/m0_37562069/article/details/102743452

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

猜你喜欢

转载自blog.csdn.net/m0_37562069/article/details/102743452