gpt4 book ai didi

java - 在 GAE 端点中传递数组

转载 作者:行者123 更新时间:2023-12-02 03:31:04 24 4
gpt4 key购买 nike

我只是尝试 GAE 端点的第一个示例,我修改了示例 API 方法以类似于此。

@ApiMethod(name = "sayHi")
public MyBean sayHi(@Named("name") String[] names) {

我的期望是接收一个字符串数组。现在,当我使用 Google API Explorer 来测试这一点时,[ https://apis-explorer.appspot.com/apis-explorer/]它生成这样的 API

POST https://myprojectid.appspot.com/_ah/api/myApi/v1/sayHi/arg1/arg2/arg3?fields=data

API explorer screenshot

它最终返回404错误。由于端点无法识别。

我在这里做错了什么?事实上,资源管理器将name显示为String而不是String[]。如有任何帮助,我们将不胜感激!

最佳答案

首先要做的事情是:当只有一个字符串参数时,这是否有效?需要使用一些 Servlet 映射魔法来公开端点,如果项目中不存在这种魔法,则事情将无法正常工作。请参阅this link确保您的 web.xml 符合预期。

看着这个link ,看来如果你的方法参数是一个基本类型(不是真正的Java对象),并且如果它没有明确包含在@Path注释中,那么你的Api中会发生什么就存在一些不确定性:

Path parameters are the method parameters included in the path property of the @ApiMethod annotation. If path is unspecified, any parameters not annotated with @Nullable or @DefaultValue will be automatically added to the path (they will be path parameters).

因此,通过在 @Path 注释中不包含“name”,文档似乎没有说明路径的格式。资源管理器正在查看的生成描述符似乎认为正确的答案是 /names[0]/names[1]/names[2],有点像 C 风格的可变参数。可能正是这种断开连接导致了 404 错误的发生。您可以尝试在 @Path 注释中包含“name”吗?

关于java - 在 GAE 端点中传递数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38083979/

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