简单更改后 REST 服务不起作用 [英] REST Service doesn't work after a simple change
问题描述
我按照本教程学习了一些 REST 服务和 AJAX 调用:http://www.mkyong.com/webservices/jax-rs/integrate-jackson-with-resteasy/
I follow this tutorial to learn some REST services and AJAX calls: http://www.mkyong.com/webservices/jax-rs/integrate-jackson-with-resteasy/
我改变了这个端点:
@GET
@Path("/get")
@Produces("application/json")
public Product getProductInJSON() {
Product product = new Product();
product.setName("iPad 3");
product.setQty(999);
return product;
}
到这个,为了返回jsonp格式的产品:
to this one, in order to return the product in the jsonp format:
@GET
@Path("/get?callback={name}")
@Produces("application/javascript")
public String getProductInJSON(@PathParam("name") String callback){
Product product = new Product();
product.setName("iPad 3");
product.setQty(999);
String productString = callback + "({" + product.toString() + "})";
return productString;
}
使用产品的 toString():
with the toString() of product:
@Override
public String toString() {
return "name:" + name + "," + "qty:" + qty;
}
但是现在,当我检查 ir URI 在浏览器中工作时,使用:
But now, when I check ir the URI works in the browser, with:
http://localhost:8080/restws/json/product/get?回调=进程
我收到此错误消息:
HTTP 错误:404
HTTP ERROR: 404
找不到相对资源:/json/product/get 的完整路径:http://localhost:8080/restws/json/product/get?callback=process
Could not find resource for relative : /json/product/get of full path: http://localhost:8080/restws/json/product/get?callback=process
RequestURI=/restws/json/product/get
RequestURI=/restws/json/product/get
有人能帮我理解为什么在这个小改动后给我这个错误吗?谢谢
Can somebody help me with understanding why it's giving me this error after this minor changing? Thanks
推荐答案
查询参数不是@Path 的一部分.您应该使用 @QueryParam 处理它们,如图所示在泽西岛用户指南中.
A query parameter isn't part of the @Path. You should handle them with @QueryParam as shown in the Jersey User Guide.
这篇关于简单更改后 REST 服务不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!