Android中的糖ORM:在SQLite中更新已保存的对象

Ton*_*yGW 5 sqlite orm android crud

我是Android上使用SQLite和Sugar ORM进行应用程序开发的新手,并尝试阅读Sugar ORM文档,但没有找到任何有关如何在SQLite中更新已保存对象的内容.我可以在更改其属性后保存对象吗?就像是:

Customer myCustomer = (Customer.find(Customer.class, "id = ?", id)).get(0);
myCustomer.setName("new name");
myCustomer.setAddress("new Address");
myCustomer.save(); // is this okay for updating the object?
Run Code Online (Sandbox Code Playgroud)

save()方法不会创建另一个新对象,同时保持旧条目不变,对吗?

Nic*_*ick 5

您的代码应该没有问题地更新行.

从文档 - 更新实体:

Book book = Book.findById(Book.class, 1);
book.title = "updated title here"; // modify the values
book.edition = "3rd edition";
book.save(); // updates the previous entry with new values.
Run Code Online (Sandbox Code Playgroud)


loo*_*e11 3

它将更新您的实体。Sugar ORM 会覆盖您现有的名称,并在 save() 方法调用后用“新名称”更新它。