java - 什么是 JAX-RS 资源?

标签 java resources jax-rs

我经常听到提到 JAX-RS 的“资源”这个词,但我不知道它是什么意思。我知道什么是 JAX-RS Web 服务。我经常创建它们,但我发现“资源”这个词非常含糊。 JAX-RS 是或可以是很多东西,所以每次我听到世界“资源”时,我的大脑都会将其解释为“神奇的神秘事物,我们不知道是什么”。用最明确的术语来说,什么是 JAX-RS 资源?是客户端吗?服务器?任何一个?还有别的东西在一起吗?资源这个词似乎到处都是,但我几乎找不到代码中 Resource 类型的 Java 对象。然后是 Spring 和 ORM 映射注释..

如果我是 911 接线员,而您在发生可怕事故后调用我让自己恢复原状,我可能会向您发送“医疗资源”。那是一个叫乔的机械师,他从护理人员学校辍学并正在骑自行车,还是救护车上的真正护理人员? ;-)

乔正在为手术做准备。有什么遗言吗?? ;-)

最佳答案

JAX-RS 资源类(参见下面的“根资源类”)用于表示 RESTful 资源。引用资料:

  1. Chapter 3 Resources

    Using JAX-RS a Web resource is implemented as a resource class and requests are handled by resource methods. This chapter describes resource classes and resource methods in detail.

    3.1 Resource Classes

    A resource class is a Java class that uses JAX-RS annotations to implement a corresponding Web resource. Resource classes are POJOs that have at least one method annotated with @Path or a request method designator.

    JSR 339: JAX-RS 2.0: The Java API for RESTful Web Services, Version 2.0 Final Release, page 11.

  2. Root resource classes are "plain old Java objects" (POJOs) that are either annotated with @Path or have at least one method annotated with @Path or a request method designator, such as @GET, @PUT, @POST, or @DELETE. Resource methods are methods of a resource class annotated with a request method designator. This section explains how to use JAX-RS to annotate Java classes to create RESTful web services.

    29.2 Creating a RESTful Root Resource Class - Java Platform, Enterprise Edition: The Java EE Tutorial (Release 7).

RESTful 资源:

5.2.1.1 Resources and Resource Identifiers

The key abstraction of information in REST is a resource. Any information that can be named can be a resource: a document or image, a temporal service (e.g. "today's weather in Los Angeles"), a collection of other resources, a non-virtual object (e.g. a person), and so on. In other words, any concept that might be the target of an author's hypertext reference must fit within the definition of a resource. A resource is a conceptual mapping to a set of entities, not the entity that corresponds to the mapping at any particular point in time.

Fielding Dissertation: CHAPTER 5: Representational State Transfer (REST).

关于java - 什么是 JAX-RS 资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45665609/

相关文章:

wpf - XamlParseException关于从资源设置图像

java - 将图像加载到 jar 中

java - JBoss EAP 6.3 + cxf 2.7.11 jax-rs 原因

java - 错误 - 返回 JSON 以及 HTTP 状态代码错误 JAX-RS

java - 如何使用 jax -rs 创建 POST 请求

java - 将图像放在另外两个上

java - 动态类加载: Exception in thread "main" java. lang.ClassFormatError

java - 如何查看 Jenkins 中与哪些工作相关的信息

java - 在 Java 中设置多个语句的执行时间

java - Jetty 和 Tomcat 之间 getResource 的差异产生文件未找到异常