最近學習JOOQ入門總結如下,
感覺JOOQ確實比較好用。
==開干==
第一步:創建表格
第二步:搭建項目
1、引入jar包 版本有陷阱
1、引入maven生成插件 版本有陷阱
3、JOOQ配置文件
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration
xmlns="http://www.jooq.org/xsd/jooq-codegen-3.13.0.xsd">
<!-- Configure the database connection here -->
<jdbc>
<driver>com.mysql.cj.jdbc.Driver</driver>
<url>jdbc:mysql://localhost:3306/library?serverTimezone=UTC&characterEncoding=utf-8
</url>
<user>root</user>
<password>root</password>
</jdbc>
<generator>
<!-- The default code generator. You can override this one, to generate
your own code style. Supported generators: - org.jooq.codegen.JavaGenerator
- org.jooq.codegen.ScalaGenerator Defaults to org.jooq.codegen.JavaGenerator -->
<name>org.jooq.codegen.JavaGenerator</name>
<database>
<!-- The database type. The format here is: org.jooq.meta.[database].[database]Database -->
<name>org.jooq.meta.mysql.MySQLDatabase</name>
<!-- The database schema (or in the absence of schema support, in your
RDBMS this can be the owner, user, database name) to be generated -->
<inputSchema>library</inputSchema>
<!-- All elements that are generated from your schema (A Java regular
expression. Use the pipe to separate several expressions) Watch out for case-sensitivity.
Depending on your database, this might be important! -->
<includes>.*</includes>
<!-- All elements that are excluded from your schema (A Java regular expression.
Use the pipe to separate several expressions). Excludes match before includes,
i.e. excludes have a higher priority -->
<excludes></excludes>
</database>
<generate>
<daos>true</daos>
<interfaces>true</interfaces>
<pojos>true</pojos>
</generate>
<target>
<!-- The destination package of your generated classes (within the destination
directory) -->
<packageName>jooq.cn.signit.testJooq.generated</packageName>
<!-- The destination directory of your generated classes. Using Maven
directory layout here -->
<directory>D:/Users/hpcq41/eclipse-workspace/mytest/jooq/src/main/java
</directory>
</target>
</generator>
</configuration>
第四步:maven編譯生成代碼
第五步:測試JOOQ基本語法
第六步:測試JOOQ關聯查詢
第七步:測試結果轉換
第八步:測試JOOQ事務