所以,我使用 Spring Boot + JOOQ + Maven。 我在JOOQ github中找到了配置,采用了它并得到了结果:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>ru.example</groupId>
<artifactId>example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>example</name>
<description>Example</description>
<properties>
<java.version>11</java.version>
<jooq.version>3.12.4</jooq.version>
<spring.datasource.driver-class-name>org.postgresql.Driver</spring.datasource.driver-class-name>
<spring.datasource.url>jdbc:postgresql://localhost:5432/example</spring.datasource.url>
<spring.datasource.username>example_user</spring.datasource.username>
<spring.datasource.password>example</spring.datasource.password>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jooq</artifactId>
<exclusions>
<exclusion>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
<version>${jooq.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-meta</artifactId>
<version>${jooq.version}</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>${jooq.version}</version>
<executions>
<execution>
<id>generate-postgres</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<jdbc>
<driver>${spring.datasource.driver-class-name}</driver>
<url>${spring.datasource.url}</url>
<user>${spring.datasource.username}</user>
<password>${spring.datasource.password}</password>
</jdbc>
<generator>
<database>
<name>org.jooq.meta.postgres.PostgresDatabase</name>
<includes>.*</includes>
<!-- <excludes></excludes>-->
<inputSchema>PUBLIC</inputSchema>
</database>
<generate>
<deprecated>false</deprecated>
<instanceFields>true</instanceFields>
<pojos>true</pojos>
</generate>
<target>
<packageName>ru.example.domain</packageName>
<directory>target/generated-sources/jooq</directory>
</target>
</generator>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
看起来像 JOOQ 示例:https://github.com/jOOQ/jOOQ/tree/master/jOOQ-examples/jOOQ-spring-boot-example
代码中没有其他配置,我不知道以后要做什么。我希望,当应用程序运行时,插件应转到 ru.example.domain
并将类生成到 target/generated-sources/jooq
中。
来自ru.example.domain
的实体示例:
public class Profile {
private Long id;
private LocalDateTime created;
private LocalDateTime updated;
private ActiveType active = ActiveType.ENABLED;
private Long userId;
private Boolean agreedToDataProcessing;
private Boolean agreedToTerms;
private String fullName;
}
但是什么也没发生。请告诉我,如何运行生成器?
最佳答案
在 PostgreSQL 中,标识符默认为小写。因此,请使用 public
而不是 PUBLIC
<inputSchema>public</inputSchema>
关于java - Spring 启动+JOOQ+MAVEN : how to generate classes?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60046256/