Java 一个类中有多个@POST标记

Java 一个类中有多个@POST标记,java,rest,post,Java,Rest,Post,在一个类/接口中是否可能有多个@POST标记。让我知道此代码是否有问题,如果有问题,原因是: @Produces("application/json") @Consumes("application/json") @Path("/user/raflets/{appId}/admin/batch/{batchId}/instance") public interface RafletJobInstanceRestService { @GET @Path("/{instanceId}") JobI

在一个类/接口中是否可能有多个@POST标记。让我知道此代码是否有问题,如果有问题,原因是:

@Produces("application/json")
@Consumes("application/json")
@Path("/user/raflets/{appId}/admin/batch/{batchId}/instance")
public interface RafletJobInstanceRestService {

@GET
@Path("/{instanceId}")
JobInstanceBean getJobInstanceDetails(@Context UriInfo uriInfo,
        @PathParam("appId") int appId, @PathParam("batchId") int batchId,
        @PathParam("instanceId") int instanceId);

@POST
@Path("/{instanceId}")
JobInstanceBean updateInstance(@Context UriInfo uriInfo,
        @PathParam("appId") int appId, @PathParam("batchId") int batchId,
        @PathParam("instanceId") int instanceId,
        JobInstanceBean batchInstance);

@POST
@Path("/clone/{instanceId}")
JobInstanceBean cloneInstance(@Context UriInfo uriInfo,
        @PathParam("appId") int appId, @PathParam("batchId") int batchId,
        @PathParam("instanceId") int instanceId,
        JobInstanceBean batchInstance);
}

我想既然每个post调用都有不同的路径,就不会有问题了,对吧?

是的,有多个
@post
注释就可以了。对于这一点,有多个
@GET
注释也很好。它们只是指定API端点应该响应的HTTP谓词


在相关注释中,如果您的API通过HTTPS服务,并且您在这些POST请求中发送敏感数据,那么您可能需要考虑将该数据作为头参数发送到报头中而不是URL中。URL中的API端点和参数仍然可见,但您的敏感数据将在标头中加密。为了做到这一点,您只需从服务中的路径中删除它们,并使用

@FormParam
而不是
@PathParam

来检索它们。是的,除了它不是restful之外,不会有任何问题。您可以按原样使用此代码。@11thdimension我想知道为什么您会说:它不会是RESTful
@POST
应该在集合中放置一个条目,所以两篇文章违反了该规则。从使用的角度来看,它仍然是完美的,但它不会是宁静的。查看这个wiki我明白了…但我仍然不明白为什么它不是RESTful,因为在同一个URI上不是同一篇文章,所以将它分离到另一个文件并有两篇文章大致相同(SoC是你的问题)@11thdimension绝对正确。REST体系结构非常严格,因为这样的服务仅限于使用HTTP谓词对特定元素执行典型的CRUD操作:GET、POST、PUT和DELETE。话虽如此,这取决于你是否严格遵守。太棒了,谢谢。我会投票给你的,但是我没有代表权哈哈,不用担心。很乐意帮忙。