gpt4 book ai didi

java - REST 为什么我们不能使用字符作为查询参数

转载 作者:行者123 更新时间:2023-11-30 03:57:17 26 4
gpt4 key购买 nike

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 库。也许这是该版本中的一些错误?

谢谢

最佳答案

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

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

关于java - REST 为什么我们不能使用字符作为查询参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22854344/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com