【发布时间】:2025-12-12 00:05:03
【问题描述】:
实体仅包含一个项目 id ,这也是主键,我在数据库中存储例如 3 个项目,当列表更新时,我需要用新的 3 个项目替换现有列表.但就我而言,它添加了新的,但我需要完全替换现有的
@Dao
public interface UserIdDao {
@Query("SELECT * FROM userIds")
Flowable<List<UserId>> allUserIds();
@Insert(onConflict = OnConflictStrategy.REPLACE)
List<Long> update(List<UserId> ids);
}
@Entity
public class UserId{
@PrimaryKey
private Long id;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
UserId userId = (UserFavoriteStore) o;
return (!id.equals(userId.id));
}
@Override
public int hashCode() {
int result = id.hashCode();
result = 31 * result + (id.hashCode());
return result;
}}
【问题讨论】:
-
"列表何时更新" -- 什么列表?
-
List
update(List ids);我的意思是 UserId 列表
标签: android persistence dao android-room