我有一个 dropwizard 应用程序来 POST/GET 查询信息。我有一个 @POST
方法,它使用我的查询及其 11 个参数填充 arrayList。为简洁起见,我将示例缩减为仅显示 3 个参数。
@Path("/query")
public class QueryResource
@GET
@Produces(MediaType.APPLICATION_JSON)
@Timed
public List<Query> getQueries() {
List<Query> queries = new ArrayList<Query>();
logger.info("Calling get queries with {} method.");
queries.add(new Query("b622d2c6-03b2-4488-9d5d-46814606e550", "eventTypeThing", "action"));
return queries;
我可以通过 ARC 发送 get 请求,它将成功返回查询的 json 表示形式。
当我尝试对特定 queryId
发出 @GET
请求并返回其特定参数时,我遇到了问题。因此,
@GET
@Path("/{queryId}/action")
public Response getAction(@PathParam("queryId") String queryId, @PathParam("action") String action){
logger.info("Get action by queryId {}");
String output = "Get action: " + action;
return Response.status(200).entity(output).build();
在其余客户端上,我向 https://localhost/query/b622d2c6-03b2-4488-9d5d-46814606e550/action
我期望返回该特定 queryId
的操作类型,但实际上返回 null。
最佳答案
您没有在方法的 @Path 注释中将“action”声明为正确的参数。您需要将其更改为:
@Path("/{queryId}/{action}")
关于java - Dropwizard Rest API 端点操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49985751/