gpt4 book ai didi

java - Spring JOOQ 生成部分失败

转载 作者:行者123 更新时间:2023-11-30 22:07:10 25 4
gpt4 key购买 nike

我是 JOOQ 的新手,在生成类时遇到问题。我有以下 Spring 配置 pom.xml

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.knodeit</groupId>
<artifactId>try</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>try</name>
<description>Demo project for Spring Boot</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
<version>3.7.4</version>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-meta</artifactId>
<version>3.7.4</version>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen</artifactId>
<version>3.7.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

<profiles>

<profile>
<id>mysql</id>
<build>
<plugins>
<plugin>

<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
</dependencies>
<configuration>
<jdbc>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost:3306</url>
<user>root</user>
<password>root</password>

</jdbc>
<generator>
<name>org.jooq.util.JavaGenerator</name>
<database>
<name>org.jooq.util.mysql.MySQLDatabase</name>
<includes>.*</includes>
<excludes />
<inputSchema>demo</inputSchema>
</database>
<generate>
<relations>true</relations>
<deprecated>false</deprecated>
<instanceFields>true</instanceFields>
<generatedAnnotation>true</generatedAnnotation>
<records>true</records>
<pojos>true</pojos>
<immutablePojos>false</immutablePojos>
<interfaces>true</interfaces>
<daos>true</daos>
<jpaAnnotations>true</jpaAnnotations>
<validationAnnotations>true</validationAnnotations>
<springAnnotations>true</springAnnotations>
<globalObjectReferences>true</globalObjectReferences>
<fluentSetters>false</fluentSetters>
</generate>
<target>
<packageName>com.knodeit.jooq.domain</packageName>
<directory>jooq</directory>
</target>
</generator>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>


</project>

当我运行 mvn clean install -P mysql 时,它连接到数据库并在配置的 jooq 文件夹下生成一堆类。但是在那之后我看到了很多错误,例如:

[ERROR] /Users/petervandeput/Documents/Development/test/try/jooq/com/knodeit/jooq/domain/tables/records/BookRecord.java:[76,25] cannot find symbol
[ERROR] symbol: method get(int)
[ERROR] location: class com.knodeit.jooq.domain.tables.records.BookRecord
[ERROR] /Users/petervandeput/Documents/Development/test/try/jooq/com/knodeit/jooq/domain/tables/records/BookRecord.java:[210,9] cannot find symbol
[ERROR] symbol: method set(int,java.lang.Integer)
[ERROR] location: class com.knodeit.jooq.domain.tables.records.BookRecord
[ERROR] /Users/petervandeput/Documents/Development/test/try/jooq/com/knodeit/jooq/domain/tables/records/BookRecord.java:[211,9] cannot find symbol
[ERROR] symbol: method set(int,java.lang.String)

有人可以提供一个 100% 工作的 pom.xml 连接到 MySql 上的模式并按其应有的方式生成吗?

最佳答案

您生成的代码以 jOOQ 3.8 为目标(例如,其中有一个 Record.get(int) 方法)。

不过,在您的依赖项中,您引用的是 jOOQ 3.7,它还没有这个方法。

您的 jOOQ 代码生成器版本和您的 jOOQ 运行时版本必须匹配。有两种解决方案:

  1. 从依赖项中删除对版本 3.7.4 的引用,并改用从 Spring Boot 引用的版本
  2. 明确设置版本 3.7.4 也作为您的代码生成版本(您目前忽略了它)

关于java - Spring JOOQ 生成部分失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41266912/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com