使用Room复制Android中的值传递Insert命令时的列表
我正在传递国家列表以将其保存在数据库使用室中。这是一种节约,但它复制了价值观,而非冲突取代了不起作用的战略使用Room复制Android中的值传递Insert命令时的列表,android,android-room,Android,Android Room,我正在传递国家列表以将其保存在数据库使用室中。这是一种节约,但它复制了价值观,而非冲突取代了不起作用的战略 AppDatabase.getAppDatabase(getApplicationContext()).countryDao().insertAllList(countryList); 列表值被复制,即使我通过了下面的替换策略 @Insert(onConflict = OnConflictStrategy.REPLACE) 这是国刀 @Dao public interface Coun
AppDatabase.getAppDatabase(getApplicationContext()).countryDao().insertAllList(countryList);
列表值被复制,即使我通过了下面的替换策略
@Insert(onConflict = OnConflictStrategy.REPLACE)
这是国刀
@Dao
public interface CountryDao {
@Query("SELECT * FROM country")
List<Country> getAllCountries();
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insertAllList(List<Country> countries);
每个国家/地区必须有不同的id并手动分配,否则每个元素的id=0并覆盖另一个 尝试不自动生成密钥
@PrimaryKey(autoGenerate = false)
private int id;
否-它不起作用,事实上,有两个列表,但它存储一个值。每个国家/地区必须有不同的id,否则每个元素的id=0并覆盖另一个。
@PrimaryKey(autoGenerate = false)
private int id;