appengine 将 User 视为附加参数

appengine sees User as additional parameter

我在我的应用程序引擎服务器上使用 OAuth。做起来相当简单,只需添加 User 作为参数之一即可。但是当我这样做时,我得到了编译错误

Multiple entity parameters. there can only be a single entity parameter per method...

@ApiMethod(path = "updateDocument", name = "updateDocument", httpMethod = ApiMethod.HttpMethod.POST)
public void updateDocument(User user, MyDocument input){
  ...
}

它适用于表单的方法

public MyBean sayHiUser(@Named("name") String name, User user)

当我有像 MyDocument 这样的自定义对象时,它就不起作用了。

我感觉你的用户不是 import com.google.appengine.api.users.User.

类型

文档指出 "there can only be a single entity parameter per method"(参见 https://cloud.google.com/appengine/docs/java/endpoints/parameter-and-return-types)。

然而 "Any type except a parameter or injected type is considered an entity type" 和 com.google.appengine.api.users.User 是类型 "injected": 所以你通常不会有任何问题,除非你的用户不是这种类型。

我个人有类似

的方法
public Customer insert(final User user, Customer customer, ...

效果很好