【Developer Log】javax ws rs实现Restful

本文介绍了如何在Java中使用RESTful服务,包括在pom文件中添加依赖,配置web.xml,以及展示GET、POST、PUT和DELETE操作的示例。强调了GET、POST、PUT和DELETE在RESTful原则下的不同用途。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.youkuaiyun.com/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

                       

如何使用RestFul

下表来自wiki说得很清楚,GET一般用于查询,POST一般用于创建,PUT用于update(如无则创建),DELETE用户删除。POST和PUT的不同在于,调用两次POST则创建两个资源,而调用两次PUT,仍关联一个资源。

                             
Uniform Resource Locator (URL) GET POST PUT DELETE
Collection, such as http://api.example.com/resources/ List the URIs and perhaps other details of the collection’s members. Replace the entire collection with another collection. Create a new entry in the collection. The new entry’s URI is assigned automatically and is usually returned by the operation. Delete the entire collection.
Element, such as http://api.example.com/resources/item17 Retrieve a representation of the addressed member of the collection, expressed in an appropriate Internet media type Replace the addressed member of the collection, or if it does not exist, create it. Not generally used. Treat the addressed member as a collection in its own right and create a new entry in it. Delete the addressed member of the collection.

Java中使用RestFul

RestFul是个web接口,因此在J2EE中使用。Spring含有对RestFul的支持,但此处,我们只讨论普通情况下如何实现Restful。

pom:关联的jar包

 <!-- 导入Bundles,可以替代Part1部分  <dependency>   <groupId>org.glassfish.jersey.bundles</groupId>   <artifactId>jaxrs-ri</artifactId>   <version>2.23.2</version> </dependency>  --> <!-- Part 1 --> <dependency>   <groupId>org.glassfish.jersey.core</groupId>   <artifactId>jersey-server</artifactId>   <version>2.23.2</version> </dependency> <dependency>   <groupId>org.glassfish.jersey.core</groupId>   <artifactId>jersey-common</artifactId>   <version>2.23.2</version> </dependency> <dependency>   <groupId>org.glassfish.jersey.containers</groupId>   <artifactId>jersey-container-servlet
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值