gpt4 book ai didi

java - 使用Resteasy开发的REST服务的@POST方法

转载 作者:行者123 更新时间:2023-12-01 11:36:43 25 4
gpt4 key购买 nike

我正在开发一个客户端/服务器应用程序。服务器端我使用 Java EE 和 Resteasy 作为库来开发 REST Web 服务。客户端我编写了一个简单的 HTML 页面来查询这些后端服务。我所做的所有服务都工作正常,除了 @POST 服务。

其代码为:

@OPTIONS
@Override
@POST
@Path("/{id}/jobs")
public void print(@PathParam("id") String deviceId,
@FormParam("doc") byte[] doc,
@FormParam("copies") int copies)
{
...
}

问题是我从前端发送到后端的字节数组到达了,但是到达时它是空的。其他输入参数正确到达后端。

我认为这个问题可以通过在方法上定义 @Consumes 来解决,但我不知道应该使用哪种“应用程序”类型。有人可以帮助我吗?

最佳答案

来自@FormParam文档:

The type T of the annotated parameter must either:

  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.

关于java - 使用Resteasy开发的REST服务的@POST方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29899200/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com