spring boot整合jooq

浪丶蕩發表於2019-01-26

專案結構:
在這裡插入圖片描述
JooqConfig.xml全文

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration>
    <jdbc>
        <driver>com.mysql.jdbc.Driver</driver>
        <url>jdbc:mysql://11.23.98.90/tableName</url>
        <user>root</user>
        <password>P@ssw0rd</password>
    </jdbc>
    <generator>
        <!-- 程式碼生成器 -->
        <name>org.jooq.util.JavaGenerator</name>
        <database>
            <!--下面這兩行是為view也生成程式碼的關鍵-->
            <!--force generating id'sfor everything in public schema, that has an 'id' field-->
            <syntheticPrimaryKeys>public\..*\.id</syntheticPrimaryKeys>
            <!--name for fake primary key-->
            <overridePrimaryKeys>override_primmary_key</overridePrimaryKeys>

            <name>org.jooq.util.mysql.MySQLDatabase</name>

            <!--include和exclude用於控制為資料庫中哪些表生成程式碼-->
            <includes>.*</includes>
            <!--<excludes></excludes>-->

            <!--資料庫名稱-->
            <inputSchema>suntree_cmp_test</inputSchema>
        </database>

        <generate>
            <!--生成dao和pojo-->
            <daos>true</daos>
            <pojos>true</pojos>
            <!--把資料庫時間型別對映到java 8時間型別-->
            <javaTimeTypes>true</javaTimeTypes>
            <!--<interfaces>true</interfaces>-->
            <!--不在生成的程式碼中新增spring註釋,比如@Repository-->
            <springAnnotations>false</springAnnotations>
        </generate>

        <target>
            <!--生成程式碼檔案的包名及放置目錄-->
            <packageName>cn.com.suntree.generator</packageName>
            <directory>src/main/java</directory>
        </target>
    </generator>
</configuration>

dependencies中加入

		<dependency>
			<groupId>org.jooq</groupId>
			<artifactId>jooq-meta</artifactId>
		</dependency>
		<dependency>
			<groupId>org.jooq</groupId>
			<artifactId>jooq-codegen</artifactId>
		</dependency>

plugins中加入

			<plugin>
				<groupId>org.jooq</groupId>
				<artifactId>jooq-codegen-maven</artifactId>
				<version>${jooq.version}</version>
				<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>
					<configurationFile>src/main/resources/JooqConfig.xml</configurationFile>
				</configuration>
			</plugin>

需要注意的都在JoopConfig.xml中做了註釋

最後執行maven的compile
將會自動生成一些程式碼
在這裡插入圖片描述
初步整合成功

相關文章