save
public void save(T entity)
"Saves" an entity to the database: depending on the existence of the key property, it will be inserted (key is null) or updated (key is not null).
This is similar to insertOrReplace(Object)
, but may be more efficient, because if a key is present, it does not have to query if that key already exists.
在官方的文档中,save是这样写的,从中可以看出,如果主键不是null的话会启动update,但要注意的是,有可能这个对象是从服务器获取回来的,这时候如果用save,但数据库里面并没有这条数据就麻烦了,要用insert,不要依赖于save。