이 방법이 있습니다.
public InsertQuery<Record> getInsertQuery(List<?> pojoList, TableImpl<Record> table) {
InsertQuery<Record> insertQuery = ctx.insertQuery(table);
pojoList.forEach(pojo -> insertQuery.addRecord(ctx.newRecord(table, pojo)));
insertQuery.setReturning();
return insertQuery;
}
기본적으로 pojoList
주어진에 삽입 될를 취하고 하나 이상의 행을 삽입하기 위해 실행할 수있는를 table
반환합니다 InsertQuery<Record>
. 하지만이 메서드를 다음과 같이 호출 할 때 :
try (DSLContext ctx = DslContextFactory.getDslContext();
InsertQuery<AttachmentsRecord> insertQuery = new AttachmentQueries(ctx)
.getInsertQuery(pojos, JOOQ_GENERATED_TABLE)) {
// do something.
}
JOOQ_GENERATED_TABLE
필요한 유형이라고 불평 TableImpl<Record>
하지만 다른 것이 제공됩니다. jooq 생성 테이블 및 레코드에 대한 일반 유형을 제공하려면 어떻게해야합니까? 정말 도움이 필요합니다.
유틸리티를 다음과 같이 변경하십시오.
public <R extends Record> InsertQuery<R> getInsertQuery(
List<?> pojoList,
Table<R> table // I recommend using Table<R> because TableImpl<R> is internal API
) {
InsertQuery<R> insertQuery = ctx.insertQuery(table);
pojoList.forEach(pojo -> insertQuery.addRecord(ctx.newRecord(table, pojo)));
insertQuery.setReturning();
return insertQuery;
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다