这是我的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]
如您所见,我的数组只有一个元素是第一个元素。 你能指出什么是错的以及如何解决它。谢谢
答案 0 :(得分:0)
使用方括号设置queryparam @QueryParam(&#34; categories []&#34;)