Java 为@GET和@POST使用相同的路径

Java 为@GET和@POST使用相同的路径,java,rest,restful-url,restful-architecture,Java,Rest,Restful Url,Restful Architecture,在JavaRESTfull服务中,我可以在同一路径中定义两个方法,并通过http调用方法进行区分 第一种方法使用GET,第二种方法使用POST @GET @Produces("application/pdf") public Response getFile(@Context HttpServletRequest req,@PathParam("search") final String search,Map<Object, Object> input) { ....} @Post

在JavaRESTfull服务中,我可以在同一路径中定义两个方法,并通过http调用方法进行区分

第一种方法使用GET,第二种方法使用POST

@GET
@Produces("application/pdf")
public Response getFile(@Context HttpServletRequest req,@PathParam("search") final String search,Map<Object, Object> input) {
....}

@Post
@Produces("application/pdf")
public Response getFile(@Context HttpServletRequest req,@PathParam("search") final String search) {
....}
@GET
@制作(“应用程序/pdf”)
公共响应getFile(@Context-HttpServletRequest-req,@PathParam(“search”)最终字符串搜索,映射输入){
....}
@职位
@制作(“应用程序/pdf”)
公共响应getFile(@Context-HttpServletRequest-req,@PathParam(“search”)最终字符串搜索){
....}

是的,在同一路径上为不同的方法使用不同的处理程序是完全有效的。

注释只是给定方法的修饰符。核心原则是,它不应该停止java类的原始结构。因此,在单个文件中使用多个处理程序是完全合法的