【发布时间】:2017-11-19 21:43:02
【问题描述】:
这是我的 REST 服务器和 POST 方法。它有一个查询参数,它是一个字符串数组
@POST
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public void create(
@HeaderParam("authorization") String token,
@QueryParam("title") String title,
@QueryParam("author") String author,
@QueryParam("path") String path,
@QueryParam("review") String review,
@QueryParam("categories") List<String> categories
) {
System.out.println("title: " + title);
System.out.println("author: " + author);
System.out.println("path: " + path);
System.out.println("review: " + review);
for(String cat: categories) {
System.out.println("categories: " + categories);
}
}
我尝试使用 POSTMAN 将此 json 发布到服务器
{
"title":"HP",
"path":"D://image/hp.jpeg",
"author":"JK",
"review":"this book is great",
"categories":["fiction", "horror","science"]
}
我希望我会收到一个包含 3 个元素的字符串数组:小说、恐怖、科学,但这是我的输出:
Info: title: HP
Info: author: JK
Info: path: D://image/hp.jpeg
Info: review: this book is great
Info: categories: [fiction]
如您所见,我的数组只有一个元素,即第一个元素。 请您指出什么是错误的以及如何解决它。谢谢
【问题讨论】: