public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public ForeignCollection getArticles() {
return articles;
}
public void setArticles(ForeignCollection articles) {
this.articles = articles;
}
@Override
public String toString() {
return “UserBean{” +
“id=” + id +
“, name=’” + name + ‘’’ +
“, sex=” + sex +
“, birthday=” + birthday +
“, address=’” + address + ‘’’ +
“, articles=” + articles +
‘}’;
}
}
关联表 ArticleBean
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
/**
-
ArticleBean实体类,存储article数据表中的数据
-
数据库中的article表和user表是关联的,因此我们需要在article表中配置外键
-
-
foreignColumnName:外键约束指向的类中的属性名
-
foreign:当前字段是否是外键
-
foreignAutoRefresh:如果这个属性设置为true,在关联查询的时候就不需要再调用refresh()方法了
*/
@DatabaseTable(tableName = “article”)
public class ArticleBean {
@DatabaseField(generatedId = true, columnName = “id”)
private int id;
@DatabaseField(columnName = “title”)
private String title;
@DatabaseField(columnName = “content”)
private String content;
@DatabaseField(columnName = “user_id”, foreign = true, foreignAutoRefresh