Spring+Mybatis-plus 实现 Gauss DB数据库代码生成

需求:

        使用的gauss db数据库(类似oracle语法),需要根据指定表生成entity、dao等代码

1,引入依赖

<?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.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>spring-boot-mybatis-generator</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>spring-boot-mybatis-generator</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- MySQL 连接驱动依赖 -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.39</version>
        </dependency>

        <!-- mybatis-starter  -->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.1</version>
        </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>

            <!-- 引入mybatis-generator 插件 -->
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.2</version>
                <configuration>
                    <!-- mybatis-generator的配置文件,根据情况调整位置 -->
                    <configurationFile>src/main/resources/mybatis-generator.xml</configurationFile>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                </configuration>
                <executions>
                    <execution>
                        <id>Generate MyBatis Artifacts</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.mybatis.generator</groupId>
                        <artifactId>mybatis-generator-core</artifactId>
                        <version>1.3.2</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

</project>

2,在resources目录下 mybatis-plus 的配置文件 mybatis-generator.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>

    <!--JDBC驱动jar包的 绝对路径,填写自己的 -->
    <classPathEntry location="D:\software\mvn-Repository\com\huawei\gauss\com.huawei.gauss.jdbc.ZenithDriver\1.5.1\com.huawei.gauss.jdbc.ZenithDriver-1.5.1.jar"/>

    <!--defaultModelType="flat" 大数据字段,不分表 -->
    <context id="Gauss" targetRuntime="MyBatis3Simple" defaultModelType="flat">
        <property name="autoDelimitKeywords" value="true" />
        <property name="beginningDelimiter" value="`" />
        <property name="endingDelimiter" value="`" />
        <property name="javaFileEncoding" value="utf-8" />
        <plugin type="org.mybatis.generator.plugins.SerializablePlugin" />

        <plugin type="org.mybatis.generator.plugins.ToStringPlugin" />

        <!-- 注释 -->
        <commentGenerator >
            <property name="suppressAllComments" value="true"/><!-- 是否取消注释 -->
            <property name="suppressDate" value="true" /> <!-- 是否生成注释代时间戳-->
        </commentGenerator>

        <!--数据库链接地址账号密码-->
        <jdbcConnection driverClass="com.huawei.gauss.jdbc.inner.GaussDriver"
                        connectionURL="jdbc:zenith:@xxxx:xxx"
                        userId="xxxx"
                        password="xxxx">
        </jdbcConnection>

        <!-- 类型转换 -->
        <javaTypeResolver>
            <!-- 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.) -->
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>

        <!--生成Model类存放位置-->
        <javaModelGenerator targetPackage="com.example.springbootmybatis.generator.entity" targetProject="src/main/java">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>

        <!-- 生成mapxml文件 -->
        <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources" >
            <property name="enableSubPackages" value="false" />
        </sqlMapGenerator>

        <!-- 生成mapxml对应client,也就是接口dao -->
        <javaClientGenerator targetPackage="com.example.springbootmybatis.generator.dao" targetProject="src/main/java" type="XMLMAPPER" >
            <property name="enableSubPackages" value="false" />
        </javaClientGenerator>

<!--        <table tableName="user" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true">-->
<!--            <generatedKey column="id" sqlStatement="Mysql" identity="true" />-->
<!--        </table>-->

<!--        <table tableName="user_role" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true">-->
<!--            <generatedKey column="id" sqlStatement="Mysql" identity="true" />-->
<!--        </table>-->
        <table tableName="t_comm_tag_config" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true">
            <generatedKey column="id" sqlStatement="Gauss" identity="true" />
        </table>

    </context>
</generatorConfiguration>

3,在idea 右上角 plugins-> mybatis-generator-> mybatis-generator:generator 双击执行,即可在指定配置中生成代码

相关推荐

  1. Spring+Mybatis-plus 实现 Gauss DB数据库代码生成

    2024-05-13 21:02:03       28 阅读
  2. Mybatis Plus代码生成code

    2024-05-13 21:02:03       45 阅读
  3. 使用代码生成器生成代码 mybatis-plus-generator

    2024-05-13 21:02:03       64 阅读
  4. mybatis plus高级应用 代码生成

    2024-05-13 21:02:03       29 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-13 21:02:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-13 21:02:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-05-13 21:02:03       82 阅读
  4. Python语言-面向对象

    2024-05-13 21:02:03       91 阅读

热门阅读

  1. puppyteer

    2024-05-13 21:02:03       34 阅读
  2. 力扣:738. 单调递增的数字

    2024-05-13 21:02:03       39 阅读
  3. 访问者模式:设计模式中的动态行为扩展

    2024-05-13 21:02:03       41 阅读
  4. SQL简介

    2024-05-13 21:02:03       36 阅读
  5. vue 自定义事件和子组件方法调用

    2024-05-13 21:02:03       29 阅读
  6. 处理Git将本地大文件上传到公共区域失败

    2024-05-13 21:02:03       36 阅读
  7. 通过实例学C#之Stack类

    2024-05-13 21:02:03       32 阅读
  8. SQLZOO:Self join

    2024-05-13 21:02:03       36 阅读
  9. MySQL sql_mode引发的异常

    2024-05-13 21:02:03       34 阅读
  10. SQLZOO:Using Null

    2024-05-13 21:02:03       40 阅读