Rest “如何编写球衣以匹配”/“你好”;及/喂?name=Mike";用不同的方法?
客户端可能会请求两个具有相同路径但不同查询字符串的URL:Rest “如何编写球衣以匹配”/“你好”;及/喂?name=Mike";用不同的方法?,rest,jersey,Rest,Jersey,客户端可能会请求两个具有相同路径但不同查询字符串的URL: 1. /hello 2. /hello?name=Mike 如何使用jersey为每种方法定义两种不同的方法 以下是一个例子: @Path("/hello") public class HelloResource { @Produces("text/plain") public String justHello() {} // how to call this method only the query
1. /hello
2. /hello?name=Mike
如何使用jersey为每种方法定义两种不同的方法
以下是一个例子:
@Path("/hello")
public class HelloResource {
@Produces("text/plain")
public String justHello() {}
// how to call this method only the query string has "name"
@Produces("text/plain")
public String helloWithName() {}
}
你不能这样做,泽西只匹配路径。有关详细信息,请参阅 您可以根据存在的查询参数构建自己的交换机。总的来说,name=mike无论如何都不是很安静。泽西岛支持:
/hello/{name}
这就是它的使用方式。实际上你可以。您只需要有一个映射到/hello/的方法来检查查询参数。如果存在,则将其作为子资源委托给另一个方法
这是一个小问题,我的程序严重依赖于此功能。你知道其他类似的库支持此功能吗?不太支持,你确定不想尝试使用REST执行此操作吗?它很流行,所以支持更好。实际上,我的客户端会发送请求,比如
PUT/users/1?method=changePwd
或PUT/users/1?method=changeName
,它使用method=name
执行不同的操作。我不想像/users/1/changeName
或/users/1/changePwd
那样在我的资源路径中包含操作
,我不知道有哪种框架能像这样工作。可悲的是,这基本上就是休息的目的/users/{name}/changePwd、/users/{name}/changeName等。