org.jooq.impl.DSL是生成所有jooq对象的主要类。作为一个静态的工厂去生成数据库表表达式、列表达式、条件表达式和其它查询部分。使用dsl时,导入org.jooq.impl.DSL.*
DSLContext和DSL 是访问JOOQ类和功能的主要入口点。
如:
创建一个常量值的字段,
Field<String> field = DSL.val("hello world");
Condition condition = DSL.exists(DSL.select(DSL.field("username")));等价于select * from 表 where exists (select username from dual);
获取表记录对象:
Table<Record> table = DSL.table("atfc_elecoco_pict");
根据数据库连接生成操作数据库的对象
DSLContext dsl = DSL.using(connection);
DSLContext引用了org.jooq.Configuration。。。Configuration配置了jooq的行为
小例子:
- DSLContext dslContext = DSL.using(connection);
- Result<Record>records = dslContext.select().from(table).where("statu = 0").and("id > 4340"