有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Update if present else使用Morphia在Play框架中插入

如果文档存在,则需要更新,否则请使用morphia in play framework插入文档。save()createIfMissing方法使用_id,但是我要基于另一个字段(比如,customId)来测试存在性。如何做到这一点


共 (1) 个答案

  1. # 1 楼答案

    Query<entityClazz> q = getDs().createQuery(entityClazz)
                              .field("customId").equal(customId)
                              .get()
    UpdateOperations<entityClazz> uop = getDs().createUpdateOperations(entityClazz)                                               .set("name", "XYZ");
    
    
    getDs().update(query, uop, true);