How to have a @PATCH annotation for JAX-RS?

前端 未结 5 565
渐次进展
渐次进展 2021-01-30 19:51

JAX-RS has annotations for HTTP verbs such as GET (@GET) and POST (@POST) but there is no @PATCH annotation. How

5条回答
  •  梦谈多话
    2021-01-30 20:10

    I got answer here.

    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 {
    }
    

    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
    

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

提交回复
热议问题