我想创建一个应用程序,存储滑板车的名称,但当我搜索名称,我得到重复,我正在使用Android的房间,这里是我的代码。任何人请帮助我,谢谢。
- POJO类 *
@PrimaryKey(autoGenerate = true)
private int id;
@ColumnInfo(name = "battery")
private String battery;
@ColumnInfo(name = "code")
private String birdCode;
@ColumnInfo(name = "latitude")
private double lat;
@ColumnInfo(name = "longitude")
private double lng;
- 道界面 *
@Query("SELECT * FROM BirdsRoom" )
List<BirdsRoom> getCachedBirds();
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insertBirds(BirdsRoom... birdsRoom);
- 如何插入数据 *
Birds birds = response.body().getBirdsList().get(i);
BirdLocation birdLocation = birds.birdLocation;
BirdLocation location = birds.birdLocation;
BirdsRoom birdsRoom = new BirdsRoom(birds.getCode(),birds.getBatteryLevel(),
birdLocation.getLat(), birdLocation.getLng());
birdsDatabase.getUserDao().insertBirds(birdsRoom);
2条答案
按热度按时间njthzxwz1#
如果你想在你的BirdsRoom中保持电池和代码的唯一性,可以设置如下注解
bwleehnv2#
如果你不想数值重复,你可以同样添加注解;