分享一下我老师大神的人工智能教程!零基础,通俗易懂!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