如何为JAX-RS提供@PATCH注释? [英] How to have a @PATCH annotation for JAX-RS?

查看:130
本文介绍了如何为JAX-RS提供@PATCH注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JAX-RS有HTTP动词的注释,例如 GET @GET )和 POST @POST )但没有 @PATCH 注释。如何为 PATCH HTTP动词添加注释?

JAX-RS has annotations for HTTP verbs such as GET (@GET) and POST (@POST) but there is no @PATCH annotation. How can I have an annotation for the PATCH HTTP verb?

如下所示:

@PATCH
public Response someCode() {
    // Code to handle the request
}


推荐答案

我得到答案在其他地方

一个只需要定义一个自定义补丁注释,这意味着您必须使用以下代码编写 PATCH.java 文件:

One will just have to define a custom Patch annotation, what that means is that you will have to write a PATCH.java file with following code:

@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@HttpMethod("PATCH")
public @interface PATCH {
}

导入包含PATCH的包。 java ,然后就像其他HTTP方法注释一样使用它:

Import the package containing PATCH.java and then you can use it like other HTTP method annotations:

@PATCH
@Path("/data/{keyspace}")
@Produces({ "application/json" })
public void patchRow(@PathParam("keyspace") String keyspace, String body) 
throws Exception

我用这个@PATCH将一些JSON发送到我的REST服务。

I used this @PATCH to send some JSON to my REST service.

这篇关于如何为JAX-RS提供@PATCH注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆