1 回答

TA贡献1827条经验 获得超9个赞
Record是接口,所以不能直接创建接口的实例,必须实例化一个实现Record接口的类,如果你使用Jooq代码生成器,你可能已经有了一个TableRecord类,这是你可以使用的类这个目的,
那么 unmapper 应该看起来像:
public class TableUnmapper implements RecordUnmapper<Table, TableRecord> {
@Override
public TableRecord unmap(Table t) throws MappingException {
TableRecord r = new TableRecord(t.getSomeAttribute());
r.setAttribute(t.getSomeOtherAttribute());
return r;
}
}
要使用解映射器:
DSLContext create;
Table table = new Table(/* Whatever Arguments */);
TableUnmapper unmapper = new TableRecordUnmapper();
// Insert
create.insertInto(TABLES).set(unmapper.unmap(table));
// update
create.executeUpdate(unmapper.unmap(table));
添加回答
举报