google-app-engine - Google Cloud Endpoint 和 Objectify

标签 google-app-engine objectify google-cloud-endpoints

我定义了一个使用 Objectify 来处理数据存储的 Google Cloud Endpoints。问题是我的模型使用了 objectify com.googlecode.objectify.Key 类。

@Entity
public class RealEstateProperty implements Serializable {

    @Id
    private Long id;
    @Parent
    private Key<Owner> owner;
    private String name;
    private Key<Address> address;

}

在我的端点中,我定义了一个创建 RealEstateProperty 的方法:

@ApiMethod(name = "create", path = "properties", httpMethod = HttpMethod.POST)
public void create(RealEstateProperty property, User user) throws Exception {
    }

API Explorer 中,create 方法需要一个表示地址的 Key 的字符串。问题是我想提供地址而不是 Key

是否可以使用 objectify 创建端点?如果是这样,您如何设计数据模型来处理 Key

最佳答案

您可以创建一个通过 API(端点)进行通信的类,其中包含一个地址字段而不是关键字段:

public class RealEstatePropertyAPI implements Serializable {

    private Long id;
    private Key<Owner> owner;
    private String name;
    private Address address;

}

在您的端点:

@ApiMethod(name = "create", path = "properties", httpMethod = HttpMethod.POST)
public void create(RealEstatePropertyAPI propertyAPI, User user) throws Exception {
    //ie: get address from propertyAPI and find in datastore or create new one.
}

或者只是向您的端点添加另一个参数。

关于google-app-engine - Google Cloud Endpoint 和 Objectify,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17918410/

相关文章:

google-app-engine - 如何在App Engine自定义运行时Dockerfile中连接到SQL实例?

java - GAE 启动动态实例来服务请求而不是使用空闲的常驻实例

java - 如何使用 ancestor() 正确存储和查询对象化实体?

java - 我的服务器端有很多 @Get 的 ReSTLet

java - 返回的 JSON 对象不尊重继承?

android-studio - Android Studio 3 - 如何添加云端点模块

node.js - App Engine 中用于本地开发的环境变量

python - 在谷歌云上训练神经网络时出现 "Unable to get Filesystem for path"错误

java - Objectify - 清理 session

java - Objectify with Endpoints for android