JAX-RS Core中的@InjectParam

时间:2015-02-02 14:23:49

标签: parameters jax-rs parameter-passing

在我们的应用程序的早期版本中,我们使用了Jersey的注释@InjectParam。现在我们要使用JAX-RS核心。 (仅导入java.ws.rs .....不依赖于JAX-RS的实现)我们使用@InjectParam作为不同@QueryParam的包装器。因此可以很长,防止相同的参数列表。

JAX-RS中有@InjectParam的替代方案吗?有人可以给我一个暗示吗?

使用@InjectParam我想避免使用长方法体,例如:

    @GET
        @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
        @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
        public Response listClusters(@QueryParam(ClusterFilter.NODE) String node,
                @QueryParam(ClusterFilter.CLUSTERNAME) String clustername,
                @QueryParam(ClusterFilter.CNAME) String cname,
                @QueryParam(ClusterFilter.STAGE) String stage,
                @QueryParam(ClusterFilter.INSTALLATIONVARIANT) String installationvariant,
                @QueryParam(ClusterFilter.BUILDNUMBER) String buildnumber,
                @QueryParam(ClusterFilter.LAS) String las,
                @QueryParam(ClusterFilter.P3270) String p3270,
                @QueryParam(ClusterFilter.LASPRETEST) String lasPretest,
                @QueryParam(ClusterFilter.P3270PRETEST) String p3270Pretest) {
.
.
.

在泽西岛的JEE5中我们有:

public Response listClustersAsHtml(@InjectParam ClusterFilterParameterConverter cFPConverter) {.....

ClusterFilterParameterConverter的定义是:

public class ClusterFilterParameterConverter {
    @QueryParam(ClusterFilter.NODE)
    private String node;

    @QueryParam(ClusterFilter.CLUSTERNAME)
    private String clustername;

    @QueryParam(ClusterFilter.CNAME)
    private String cname;

    @QueryParam(ClusterFilter.STAGE)
    private String stage;

    @QueryParam(ClusterFilter.INSTALLATIONVARIANT)
    private String installationvariant;

    @QueryParam(ClusterFilter.BUILDNUMBER)
    private String buildnumber;

    @QueryParam(ClusterFilter.LAS)
    private String las;

    @QueryParam(ClusterFilter.P3270)
    private String p3270;

    @QueryParam(ClusterFilter.LASPRETEST)
    private String lasPretest;

    @QueryParam(ClusterFilter.P3270PRETEST)
    private String p3270Pretest;....

0 个答案:

没有答案