Java 在Jersey中将int数组作为@QueryParam发送

Java 在Jersey中将int数组作为@QueryParam发送,java,jersey,Java,Jersey,我正在尝试编写一个GET方法,并将int数组作为QueryParam发送给它。这就是我试图做到的: @GET @Path("/test") @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public Response test(@Context HttpServletRequest request, @QueryParam("list") final int list[]) { Sys

我正在尝试编写一个GET方法,并将int数组作为QueryParam发送给它。这就是我试图做到的:

@GET
@Path("/test")
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response test(@Context HttpServletRequest request,
        @QueryParam("list") final int list[])
{
    System.out.println(list.length);
    return Response.ok().build();
}

这导致500个内部服务器错误。当我尝试使用整数列表时,它工作得非常好。Jersey不支持数组作为参数,还是我做错了什么?

Jersey中的实现不支持数组作为参数。由于需要将其作为数组传递,只需使用数组将列表转换为数组即可。asList(arr)

java文档说明方法参数的类型应为:

1) Be a primitive type;
2) Have a constructor that accepts a single String argument;
3) Have a static method named valueOf or fromString that accepts a single String argument (see, for example, Integer.valueOf(String))
4) Be List, Set or SortedSet, where T satisfies 2 or 3 above. The resulting collection is read-only.
有时参数可能包含多个相同名称的值。如果是这种情况,则可以使用4)中的类型来获取所有值


因此,在这种情况下,使用数组是不可能的。

请尝试@QueryParam(“list”)设置list?@JekinKalariya我需要传递int的数组,为什么我要尝试呢?jersy会将数组转换为list或Set,只要尝试一下,无论是否有效