我遇到了将我的模型类添加到Room数据库的问题。我读过@Relation,@ Embedded,但我无法弄清楚如何处理我的模型类。
这是我的模型类来自服务器。我需要存储这些数据
public class ResultsItem {
private String model;
private int id;
private int distanceLon;
private String brand;
//*PROMBLEM HERE*
private List<BidsItem> bids;
//*PROMBLEM HERE*
private User user;
//*PROMBLEM HERE*
private List<FotosItem> fotos;
// getters/setters...
}
FotosItem类
public class FotosItem {
private String imageUrl;
private int resultItemId;
private int id;
//getters/setters
}
BidsItem类
public class BidsItem {
private double distanceToAuto;
private boolean isWin;
private int sum;
private String currency;
private int id;
//getters/setters
}
如果有人告诉我我需要做什么,或者至少要朝哪个方向移动,我将非常感激
答案 0 :(得分:1)
你可以通过在DAO类中做一些tweek来实现它。对列表使用忽略注释。
public class FotosItem {
private String imageUrl;
private int resultItemId;
private int id;
//getters/setters
}
FotosItem类
public class BidsItem {
private double distanceToAuto;
private boolean isWin;
private int sum;
private String currency;
private int id;
//getters/setters
}
BidsItem类
@Dao
public abstract class DBAccess {
@Insert
public abstract void insertBids(List<BidsItem> pets);
@Insert
public abstract void insertFotos(List<FotosItem> pets);
@Insert
public abstract void insertResultItem(ResultsItem resultItem);
public void insertResultWithBidsFotos(ResultsItem resultItem) {
insertBids(resultItem.getBids());
insertFotos(resultItem.getFotos());
insertResultItem(resultItem);
}
}
现在DAO班
http://localhost:8080/
您可以实施以进行检索。