【发布时间】:2019-02-21 17:46:05
【问题描述】:
我有以下 Java 类:
public class Font {
private String fontFamily;
private int fontSize;
// other members and getters/setters
}
这个类中用到了Font类:
public class RichText {
private int code;
private String richString;
private Font titleFont;
private Font subtitleFont;
// other members and getters/setters
}
现在,我在数据库中有一个表来存储RichText,请注意,我将字体类展平以避免创建额外的表:
CREATE TABLE rich_text (
code int,
rich_string text,
fontTitleFamily varchar(20),
fontTitleSize int,
fontSubtitleFamily varchar(20),
fontSubtitleSize int,
.....
);
我使用 Jooq 读取了rich_text 表,如下所示:
Record rec = create.select()
.from(RICH_TEXT)
.where(RICH_TEXT.CODE.eq(code))
.fetchAny();
if (rec == null)
throw new RecordNotFoundException();
RichText richText = new RichText();
rec.into(richText);
但这不会填充字体类,因为名称不同。我不想规范化这个表格,因为它只有两种字体。
Jooq 中有没有办法在生成器中注释或配置数据库中的列与子类的字段之间的关系?
【问题讨论】: