gpt4 book ai didi

java - SwaggerUi REST 方法 - 方法生成和使用完全相同的 mime 类型

转载 作者:行者123 更新时间:2023-12-01 09:38:28 25 4
gpt4 key购买 nike

我正在尝试使用 swaggeUI 创建 REST 方法。

一种通过 id 搜索 User 的方法,另一种通过 firstName 搜索 User 的方法,如下所示:

@Produces( { MediaType.APPLICATION_JSON } )
@Path( "/{firstName}" )
@GET
@ApiOperation( value = "Find User by e-mail", notes = "Find User by e-mail", response = User.class )
@ApiResponses( {
@ApiResponse( code = 404, message = "User with such e-mail doesn't exists" )
} )
public User getUserByFirstName( @ApiParam( value = "E-Mail address to lookup for", required = true ) @PathParam( "email" ) final String email );


@GET
@Path("/{userId}")
@Nullable
@Produces(MediaType.APPLICATION_JSON)
User getUserById(@Nonnull @PathParam("userId") Long userId);

构建代码时出现此错误:

Following issues have been detected: WARNING: A resource model has ambiguous (sub-)resource method for HTTP method GET and input mime-types as defined by"@Consumes" and "@Produces" annotations at Java methods User getUserByFirstName(java.lang.String) and public abstract User getUserById(java.lang.Long) at matching regular expression /([^/]+). These two methods produces and consumes exactly the same mime-types and therefore their invocation as a resource methods will always fail. WARNING: The (sub)resource method indexUsers in UserService contains empty path annotation.

我是 REST 新手,我需要帮助才能解决此问题。

谢谢

最佳答案

尝试更改您的@Path 定义。它无法判断 Long 应该是数字还是字符串 {firstname} 可以是 Long。

尝试:

@Path("/name/{firstname}")
....
@Path("/id/{userid}")

关于java - SwaggerUi REST 方法 - 方法生成和使用完全相同的 mime 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38643205/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com