我是在 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?
save() 方法不会在保持旧条目不变的情况下创建另一个新对象,对吗?
最佳答案
您的代码应该可以毫无问题地更新该行。
From the docs - Update Entity :
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.
关于android - Android 中的 Sugar ORM : update a saved object in SQLite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26835785/