@POST in RESTful web service(RESTful Web 服务中的@POST)
问题描述
我一直在尝试使用 Jersey 来理解 RESTful Web 服务中的 @POST.我已经浏览了 http://www.vogella.com/articles/REST/article.html一样,并且能够获得有关@POST 的一些信息,但感到困惑和笨拙.任何人都可以用一个简单的例子来解释@POST 或者分享相同的链接.
I have been trying to understand @POST in RESTful web service using Jersey. I have gone through http://www.vogella.com/articles/REST/article.html for the same and was able to get some information about @POST, but felt confusing and clumpsy. Can anyone explain @POST with a simple example or share links about the same.
通过上面链接中的 TODO 对象实现 @POST 很好,但我希望通过其他一些简单的示例来学习 @POST,以便我可以继续开发自己的复杂 @POST 示例.
Implementing @POST through TODO objects in above link was fine but i wish to learn @POST through some other simple example so that i can go ahead to develop my own complex @POST examples.
帮助将是明显的,谢谢.
Help will be appreciable, Thanks.
推荐答案
请看下面的例子,它可能对你有帮助
Please find example below, it might help you
package jersey.rest.test;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.HEAD;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
@Path("/hello")
public class SimpleService {
@GET
@Path("/{param}")
public Response getMsg(@PathParam("param") String msg) {
String output = "Get:Jersey say : " + msg;
return Response.status(200).entity(output).build();
}
@POST
@Path("/{param}")
public Response postMsg(@PathParam("param") String msg) {
String output = "POST:Jersey say : " + msg;
return Response.status(200).entity(output).build();
}
@POST
@Path("/post")
//@Consumes(MediaType.TEXT_XML)
public Response postStrMsg( String msg) {
String output = "POST:Jersey say : " + msg;
return Response.status(200).entity(output).build();
}
@PUT
@Path("/{param}")
public Response putMsg(@PathParam("param") String msg) {
String output = "PUT: Jersey say : " + msg;
return Response.status(200).entity(output).build();
}
@DELETE
@Path("/{param}")
public Response deleteMsg(@PathParam("param") String msg) {
String output = "DELETE:Jersey say : " + msg;
return Response.status(200).entity(output).build();
}
@HEAD
@Path("/{param}")
public Response headMsg(@PathParam("param") String msg) {
String output = "HEAD:Jersey say : " + msg;
return Response.status(200).entity(output).build();
}
}
对于测试,您可以使用任何工具,例如 RestClient (http://code.google.com/p/rest-client/)
for testing you can use any tool like RestClient (http://code.google.com/p/rest-client/)
这篇关于RESTful Web 服务中的@POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:RESTful Web 服务中的@POST
基础教程推荐
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- Struts2 URL 无法访问 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
