29.5.2 使用DSLContext
jOOQ提供的流式(fluent)API是通过org.jooq.DSLContext接口初始化的,Spring Boot将自动配置一个DSLContext为Spring Bean,并将它跟应用的DataSource连接起来。想要使用DSLContext,只需@Autowire注入它:
@Component
public class JooqExample implements CommandLineRunner {
    private final DSLContext create;
    @Autowired
    public JooqExample(DSLContext dslContext) {
        this.create = dslContext;
    }
}注 jOOQ手册倾向于使用一个名为create的变量持有DSLContext。
然后你就可以使用DSLContext构造查询,如下所示:
public List<GregorianCalendar> authorsBornAfter1980() {
    return this.create.selectFrom(AUTHOR)
        .where(AUTHOR.DATE_OF_BIRTH.greaterThan(new GregorianCalendar(1980, 0, 1)))
        .fetch(AUTHOR.DATE_OF_BIRTH);
}最后更新于
这有帮助吗?