有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在JAXRS2中处理格式查询参数?

我想公开RESTAPI。 我想知道使用format查询参数返回资源的格式是什么? 基于此,我想选择合适的控制器

例如: GET /resources/sub-resources?format={valid_formats}&queryParam1={some-selector}........

我想要能做到这一点的东西

@Path("resources/sub-resources")
public interface SubResource {
    @GET
    Response getSubResourceFormatBase64(@QueryParam("queryParam1") queryParam1);

    @GET
    Response getSubResourceFormatPlainString(@QueryParam("queryParam1") queryParam1);
}

而不是这个

@Path("resources/sub-resources")
public interface SubResource {
    @GET
    Response getSubResource(@QueryParam("format") format, @QueryParam("queryParam1") queryParam1);
}

并选择如何返回格式类型。 我如何做到这一点

注意:格式必须是查询参数


共 (1) 个答案

  1. # 1 楼答案

    为什么不这样做:

    @Path("resources/sub-resources")
    public interface SubResource {
        @GET
        @Path("/base64")
        Response getSubResourceFormatBase64(@QueryParam("queryParam1") queryParam1);
    
        @GET
        @Path("/plainString")
        Response getSubResourceFormatPlainString(@QueryParam("queryParam1") queryParam1);
    }
    

    所以格式应该是路径变量之类的