我已在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;
答案 0 :(得分:1)
路径变量必须在请求映射中用大括号括起来。 在您的代码中,以下行
@RequestMapping(value = "/uuid", method = { RequestMethod.GET })
可以更改为
@RequestMapping(value = "/{uuid}", method = { RequestMethod.GET })
要修复该错误。