📜  RESTful Web服务-Java(JAX-RS)

📅  最后修改于: 2020-10-20 04:39:28             🧑  作者: Mango


JAX-RS代表用于RESTful Web服务的JAVA API。 JAX-RS是基于Java的编程语言API和规范,可为创建的RESTful Web服务提供支持。其2.0版本已于2013年5月24日发布。JAX-RS使用Java SE 5中可用的注释来简化基于JAVA的Web服务创建和部署的开发。它还为创建RESTful Web服务的客户端提供支持。

技术指标

以下是将资源映射为Web服务资源的最常用注释。

Sr.No. Annotation & Description

1

@Path

Relative path of the resource class/method.

2

@GET

HTTP Get request, used to fetch resource.

3

@PUT

HTTP PUT request, used to update resource.

4

@POST

HTTP POST request, used to create a new resource.

5

@DELETE

HTTP DELETE request, used to delete resource.

6

@HEAD

HTTP HEAD request, used to get status of method availability.

7

@Produces

States the HTTP Response generated by web service. For example, APPLICATION/XML, TEXT/HTML, APPLICATION/JSON etc.

8

@Consumes

States the HTTP Request type. For example, application/x-www-formurlencoded to accept form data in HTTP body during POST request.

9

@PathParam

Binds the parameter passed to the method to a value in path.

10

@QueryParam

Binds the parameter passed to method to a query parameter in the path.

11

@MatrixParam

Binds the parameter passed to the method to a HTTP matrix parameter in path.

12

@HeaderParam

Binds the parameter passed to the method to a HTTP header.

13

@CookieParam

Binds the parameter passed to the method to a Cookie.

14

@FormParam

Binds the parameter passed to the method to a form value.

15

@DefaultValue

Assigns a default value to a parameter passed to the method.

16

@Context

Context of the resource. For example, HTTPRequest as a context.

–在RESTful Web服务-第一个应用程序RESTful Web服务-方法章节中,我们使用了Jersey(Oracle的JAX-RS 2.0的参考实现)。