如何解决““ UUID类型的方法参数缺少URI模板变量'uuid'”?

时间:2019-01-03 11:39:28

标签: java spring-boot spring-mvc

我已在spring-boot实现的Web应用程序的控制器中将路径变量从String更新为UUID。我正在用招摇的前端。更改后,响应中出现“缺少UUID类型的方法参数的URI模板变量'uuid'”异常。

我已在spring-boot实现的Web应用程序的控制器中将路径变量从String更新为UUID。我正在用招摇的前端。在数据库方面,我正在使用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;
  1. 它应该是将结果获取给我。现在,它引发异常。它甚至没有到达控制器,怀疑是一些Spring配置依赖项。不知道那是什么吗?

1 个答案:

答案 0 :(得分:1)

路径变量必须在请求映射中用大括号括起来。 在您的代码中,以下行

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

可以更改为

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

要修复该错误。