REST为什么我们不能将字符作为查询参数

时间:2014-04-04 05:33:37

标签: java rest jersey-1.0

Tomcat 7.0无法启动以下方法定义

@GET
    @Path("/GetSeriesByIndex")
    @Produces("application/json")
    public String getSeriesListByIndex(@QueryParam("indexCharacter")char indexCharacter){
        String allSeriesByIndex = null;
        ArrayList<SeriesListDTO> seriesListing=null;
        try{
            ProjectManager projectManager = new ProjectManager();
            seriesListing = projectManager.getSeriesListByIndex(indexCharacter);
            Gson gson = new Gson();
            allSeriesByIndex = gson.toJson(seriesListing);
        }catch(Exception e){
            System.out.println(e);
        }
        return allSeriesByIndex;
    }

带有错误消息

com.sun.jersey.api.container.ContainerException: Method, public java.lang.String tv.series.services.webService.TV_Services.getSeriesListByIndex(char), annotated with GET of resource, class tv.series.services.webService.TV_Services, is not recognized as valid Java method annotated with @HttpMethod.

在将indexCharacter的类型更改为String时,系统会启动,一切正常。

有人可以解释为什么会这样吗?

我正在使用jersey 1.0.3个库。也许是那个版本中的一些错误?

由于

1 个答案:

答案 0 :(得分:2)

这是泽西岛的api文档:https://jersey.java.net/apidocs/2.7/jersey/javax/ws/rs/QueryParam.html

将字符串转换为char?为什么不使用String?