【问题标题】:Restful webservice Query param issueRestful webservice查询参数问题
【发布时间】:2012-08-03 09:03:32
【问题描述】:

我们在项目中使用了 Restful Web 服务。我将以下类的对象作为查询参数传递给我的网络服务。

public class QueryDTO {
    private String name;
    private Object[] args;
    private Object[] results;
//with setters and getters
}

这是我的网络服务配置

@GET
@Produces("application/json")
@Path("/")
QueryDTO executeQuery(@QueryParam("") QueryDTO queryDTO) throws Exception;

这里的 args 可能包含任何数据类型(字符串、整数、日期等) 当我打电话时

rest/query?name="getCreativeExtractorPatternByName"&args={"473"}

我遇到了异常。

Parameter Class java.lang.Object has no constructor with single String parameter, static valueOf(String) or fromString(String) methods

请帮我解决这个问题..

【问题讨论】:

  • 我不认为你可以在查询参数中给出一个数组,这就是为什么会出现异常!而且您不需要将查询参数的值放在双引号中

标签: java rest


【解决方案1】:

添加单个参数构造函数:

public QueryDTO(String name) {
  this.name = name;
}

为了将参数注入 DTO 对象,它应该包含一个接受字符串参数的构造函数。

您应该为您的 DTO 对象中的成功注入提供有效的查询参数。

【讨论】:

  • 你能解释一下,为什么我们需要这个?同时,我会尝试并让您知道。
猜你喜欢
  • 2023-03-23
  • 1970-01-01
  • 2012-04-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-05
相关资源
最近更新 更多