简体   繁体   English

当我们在同一方法上添加@GET和@Consumes时会发生什么

[英]What happens when we add @GET and @Consumes on the same method

Is there any scenario or side-effect when we want to write write @javax.ws.rs.GET and @javax.ws.rs.Consumes at the same time on the same method? 当我们想同时使用同一方法编写@ javax.ws.rs.GET和@ javax.ws.rs.consums时,是否有任何场景或副作用?

Documentation for javax.ws.rsConsumes says "A container is responsible for ensuring that the method invoked is capable of consuming the media type of the HTTP request entity body" and GET does not have body, but using both annotations is allowed (ie no exception or any warning). javax.ws.rsConsumes的文档说:“容器负责确保所调用的方法能够使用HTTP请求实体主体的媒体类型”,而GET没有主体,但是允许使用两个注释(即,无例外)或任何警告)。

Oracle Doc's says 甲骨文医生说

The @Consumes annotation is used to specify the MIME media types of representations a resource can consume that were sent by the client. @Consumes批注用于指定客户端可以发送的资源可以使用的表示形式的MIME媒体类型。

Link to Documentation: click ! 链接到文档: 单击

I don't think that there is gonna be a side effect. 我认为不会有副作用。 Here's an example from the documentation: 这是文档中的示例:

@POST
@Consumes("text/plain")
public void postClichedMessage(String message) {
    // Store the message
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我们调用ArrayList.add()方法时会发生什么? - What happens when we call ArrayList.add() method? 当我们在Java中有两个具有相同名称的类时会发生什么? - what happens when we have two classes with same names in java? 当我们明确调用Garbage collector方法时会发生什么? - What happens when we explicitly call Garbage collector method? 当我们在 onCreate() 方法中调用 finish() 时会发生什么? - What happens when we call finish() in onCreate() method? 当少数线程尝试调用相同的同步方法时会发生什么? - What happens when few threads trying to call the same synchronized method? 在Java中同时访问同步方法时会发生什么? - What happens when a synchronized method is accessed at the same time in java? 两个具有相同方法名称的接口,当我覆盖时会发生什么? - Two interfaces with same method name, what happens when I override? 当我们提交时到底发生了什么? - What happens exactly when we commit? 当我们使用类实例调用静态方法/函数时会发生什么? - What happens when we call a static method/function using class instance? 了解我们在调用super.clone和不调用super.clone时覆盖clone方法时会发生什么情况? - Understanding what happens when we override the clone method with and without invoking super.clone?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM