configuration/jdbc tag ile JDBC bağlantısı belirtilir
configuration/jdbc tag ile JDBC bağlantısı belirtilir
configuration/generator Tag
configuration/generator tag ile üretilecek kod için ayarlar belirtilir
Örnek - POJO Üretmek
Şöyle yaparız
<plugin><groupId>org.jooq</groupId><artifactId>jooq-codegen-maven</artifactId><executions><execution><id>generate-postgres</id><phase>generate-sources</phase><goals><goal>generate</goal></goals><configuration><!-- JDBC connection parameters --><jdbc><driver>${datasource.driver}</driver><url>${datasource.jdbcUrl}</url><user>${datasource.username}</user><password>${datasource.password}</password></jdbc><!-- Generator parameters --><generator><database><name>org.jooq.meta.postgres.PostgresDatabase</name><includes>.*</includes><excludes/><inputSchema>public</inputSchema></database><generate><pojos>true</pojos><pojosEqualsAndHashCode>true</pojosEqualsAndHashCode><javaTimeTypes>true</javaTimeTypes><fluentSetters>true</fluentSetters></generate><target><packageName>com.example.springbootjooq.model</packageName><directory>target/generated-sources/jooq</directory></target></generator></configuration></execution></executions></plugin>
Çalıştırmak için şöyle yaparız. Çıktı target/generated-sources/jooq dizinindedir
mvn clean generate-sources
Örnek - DAO
Şöyle yaparız. Burada DAO üretiliyor ve DAO'lar Spring anotasyonları kullanıyor.
<generate> <pojos>true</pojos> <pojosEqualsAndHashCode>true</pojosEqualsAndHashCode> <javaTimeTypes>true</javaTimeTypes> <fluentSetters>true</fluentSetters> <!-- Generate the DAO classes --> <daos>true</daos> <!-- Annotate DAOs (and other types) with spring annotations, such as @Repository and @Autowired for auto-wiring the Configuration instance, e.g. from Spring Boot's jOOQ starter --> <springAnnotations>true</springAnnotations> <!-- Generate Spring-specific DAOs containing @Transactional annotations --> <springDao>true</springDao> </generate>
Örnek - Kotlin
Şöyle yaparız.
<plugin> <groupId>org.jooq</groupId> <artifactId>jooq-codegen-maven</artifactId> <!--1--> <executions> <execution> <id>jooq-codegen</id> <phase>generate-sources</phase> <goals> <goal>generate</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>org.postgresql</groupId> <!--2--> <artifactId>postgresql</artifactId> <version>42.6.0</version> </dependency> </dependencies> <configuration> <generator> <name>org.jooq.codegen.KotlinGenerator</name> <!--3--> <database> <inputSchema>people</inputSchema> <!--4--> </database> <target> <packageName>ch.frankel.blog.reactivedata.jooq</packageName> </target> </generator> <jdbc> <!--4--> <driver>org.postgresql.Driver</driver> <url>jdbc:postgresql://localhost:5432/postgres</url> <user>postgres</user> <password>root</password> </jdbc> </configuration> </plugin>
Açıklaması şöyle
1. The version is defined in the parent Spring Boot Starter parent POM2. Set the necessary database driver(s). Note that one should use the non-reactive driver3. There's a Kotlin generator!4. Configure database configuration parameters