Java 如何修复'&引用;缺少URI模板变量';uuid';对于UUID类型的方法参数';?

Java 如何修复'&引用;缺少URI模板变量';uuid';对于UUID类型的方法参数';?,java,spring-boot,spring-mvc,Java,Spring Boot,Spring Mvc,我已经在spring boot实现的web应用程序的控制器中将pathvariable从String更新为UUID。我使用的前端招摇过市。更改后的响应中出现“uuid类型的方法参数缺少URI模板变量“uuid”异常 我已经在spring boot实现的web应用程序的控制器中将pathvariable从String更新为UUID。我使用的前端招摇过市。在db端,我使用mongodb。我正在将这个uuid转换为字符串,以使用为mongodb实现的现有find方法。我在回复中得到了这个异常。同样的东

我已经在spring boot实现的web应用程序的控制器中将pathvariable从String更新为UUID。我使用的前端招摇过市。更改后的响应中出现“uuid类型的方法参数缺少URI模板变量“uuid”异常

我已经在spring boot实现的web应用程序的控制器中将pathvariable从String更新为UUID。我使用的前端招摇过市。在db端,我使用mongodb。我正在将这个uuid转换为字符串,以使用为mongodb实现的现有find方法。我在回复中得到了这个异常。同样的东西正在另一个项目中工作,无法找到它为什么不在这里工作

@Path("/uuid")
@RequestMapping(value = "/uuid", method = { RequestMethod.GET })
@ResponseBody
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value = "Retrieves result based on Unique Identifier", notes = "Returns result matching with the Unique Identifier", 
    position = 1, response = Response.class, httpMethod = "GET")
@ApiResponses(value = { @ApiResponse(code = HttpServletResponse.SC_BAD_REQUEST, message = "Invalid request."),
        @ApiResponse(code = HttpServletResponse.SC_NOT_FOUND, message = "Record not found."),
        @ApiResponse(code = HttpServletResponse.SC_FORBIDDEN, message = "Not authorized for this operation."),
        @ApiResponse(code = HttpServletResponse.SC_CONFLICT, message = "Object state out-of-date."),
        @ApiResponse(code = HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message = "Server error") })
ResponseEntity<Response> getResultByUuid(@ApiParam(required = true, name = "uuid", value = "uuid") @PathParam("uuid") @PathVariable("uuid") UUID uuid,
        @ApiParam(access = "hidden") HttpServletRequest request)
        throws IOException;
@Path(“/uuid”)
@RequestMapping(value=“/uuid”,method={RequestMethod.GET})
@应答器
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value=“根据唯一标识符检索结果”,notes=“返回与唯一标识符匹配的结果”,
position=1,response=response.class,httpMethod=“GET”)
@ApiResponses(value={@ApiResponse(code=HttpServletResponse.SC_BAD_请求,message=“无效请求”),
@ApiResponse(code=HttpServletResponse.SC\u未找到,message=“记录未找到”),
@ApiResponse(code=HttpServletResponse.SC_禁止,message=“未对此操作授权”),
@ApiResponse(code=HttpServletResponse.SC_冲突,message=“对象状态已过期”),
@ApiResponse(code=HttpServletResponse.SC\u INTERNAL\u SERVER\u ERROR,message=“SERVER ERROR”)}
ResponseEntity GetResultByUID(@ApiParam(required=true,name=“uuid”,value=“uuid”)@PathParam(“uuid”)@PathVariable(“uuid”)uuid uuid,
@ApiParam(access=“hidden”)HttpServletRequest请求
抛出IOException;
  • 它应该给我取回结果。现在它抛出异常。它甚至没有到达控制器,怀疑一些spring配置依赖性的东西。不知道那是什么

  • 路径变量必须在花括号中的请求映射中提及。 在代码中,输入以下行

    @RequestMapping(value = "/uuid", method = { RequestMethod.GET })
    
    可以改为

    @RequestMapping(value = "/{uuid}", method = { RequestMethod.GET })
    

    为了修复这个错误。

    通过这些更改,我最终遇到了“为HTTP路径映射的不明确处理程序方法”异常。然后我发现父类具有相同的路径,所以制作@RequestMapping(value=“uuid/{uuid}”,method={RequestMethod.GET})为我解决了这个问题。谢谢你的提示。对我来说,为父对象映射到
    /…/uuid
    的请求看起来很不寻常。如果API路径的命名约定基于模型的语义,这将意味着您将单个UUID公开为资源,子路径将映射到该UUID的属性——您的代码示例并非如此。如果这不是您的意图,我建议您更改parent的映射,并保留child的
    /{uuid}
    。示例:
    /api/v1/users
    用于所有用户(父用户)的集合,而
    /api/v1/users/{uuid}
    用于特定用户(子用户)。由于父类来自一个框架,在项目内部,我们实际上无法修改它。@RequestMapping在类和父类的组合中必须是唯一的,所以我刚刚修改了我的类(子类)的请求映射,并且它工作了