美文网首页程序员Java 杂谈Java
SpringBoot环境中使用MyBatis代码生成工具

SpringBoot环境中使用MyBatis代码生成工具

作者: 88b61f4ab233 | 来源:发表于2019-06-11 20:43 被阅读21次

    一、Maven配置文件中添加如下依赖

    <dependency>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-core</artifactId>
                <version>1.3.7</version>
            </dependency>
    
    <plugin>
                    <groupId>org.mybatis.generator</groupId>
                    <artifactId>mybatis-generator-maven-plugin</artifactId>
                    <version>1.3.4</version>
                    <dependencies>
                        <dependency>
                            <groupId>mysql</groupId>
                            <artifactId>mysql-connector-java</artifactId>
                            <version>5.1.38</version>
                        </dependency>
                    </dependencies>
                    <configuration>
                        <verbose>true</verbose>
                        <overwrite>true</overwrite>
                        <configurationFile>${basedir}/src/main/resources/generatorConfig.xml</configurationFile>
                    </configuration>
                </plugin>
    

    二、添加generatorConfig.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 >
        <!-- mysql jar 文件位置 -->
        <classPathEntry location="F:/instrument\maven/.m2/repository/mysql/mysql-connector-java/5.1.38/mysql-connector-java-5.1.38.jar" />
        <context id="store" targetRuntime="MyBatis3">
            <commentGenerator>
                <!-- 是否去除自动生成的注释 true:是 : false:否 -->
                <property name="suppressAllComments" value="true" />
                <!-- 是否去除所有自动生成的文件的时间戳,默认为false -->
                <!-- <property name="suppressDate" value="false"/> -->
            </commentGenerator>
            <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
            <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
                            connectionURL="jdbc:mysql://127.0.0.1:3306/g"
                            userId="root"
                            password="root">
            <!--<jdbcConnection driverClass="com.mysql.jdbc.Driver"
                            connectionURL="jdbc:mysql://112.35.82.91:3360/benevolenceParking"
                            userId="renrenbang"
                            password="05377975333">-->
            </jdbcConnection>
            <!-- targetPackage:包名称(自定义)  targetProject:项目路径(自定义)   -->
            <javaModelGenerator targetPackage="com.zblx.park.po" targetProject="src/main/java">
                <!-- enableSubPackages:是否让schema作为包的后缀 -->
                <property name="enableSubPackages" value="false" />
                <!-- 从数据库返回的值被清理前后的空格  -->
                <property name="trimStrings" value="true" />
            </javaModelGenerator>
            <!-- 配置生成相应的实体Mapper.xml,对于Mapper3.X我们需要把type="XMLMAPPER" -->
            <!-- targetPackage:包名称(自定义)  targetProject:项目路径(自定义)   -->
            <sqlMapGenerator targetPackage="com.zblx.park.mapper" targetProject="src/main/java">
                <property name="enableSubPackages" value="false" />
            </sqlMapGenerator>
            <!-- 配置生成相应的接口类,对应与Mapper.xml中的一系列CRUD方法SQL语句 -->
            <!-- targetPackage:包名称(自定义)  targetProject:项目路径(自定义)   -->
            <javaClientGenerator targetPackage="com.zblx.park.dao" targetProject="src/main/java" type="XMLMAPPER">
                <property name="enableSubPackages" value="false" />
            </javaClientGenerator>
            <!-- 用户表-->
            <!--<table schema="benevolenceParking" tableName="parking" domainObjectName="Parking"
                   enableCountByExample="false"
                   enableUpdateByExample="false"
                   enableDeleteByExample="false"
                   enableSelectByExample="false"
                   selectByExampleQueryId="false"
            >-->
            <table schema="fruit" tableName="parking" domainObjectName="Parking"
                   enableCountByExample="false"
                   enableUpdateByExample="false"
                   enableDeleteByExample="false"
                   enableSelectByExample="false"
                   selectByExampleQueryId="false"
            />
            <table schema="fruit" tableName="orders" domainObjectName="Orders"
                   enableCountByExample="false"
                   enableUpdateByExample="false"
                   enableDeleteByExample="false"
                   enableSelectByExample="false"
                   selectByExampleQueryId="false"
            >
            </table>
            <table schema="fruit" tableName="car" domainObjectName="Car"
                   enableCountByExample="false"
                   enableUpdateByExample="false"
                   enableDeleteByExample="false"
                   enableSelectByExample="false"
                   selectByExampleQueryId="false"
            >
            </table>
            <table schema="fruit" tableName="carlock" domainObjectName="CarLock"
                   enableCountByExample="false"
                   enableUpdateByExample="false"
                   enableDeleteByExample="false"
                   enableSelectByExample="false"
                   selectByExampleQueryId="false"
            >
            </table>
        </context>
    </generatorConfiguration>
    

    相关文章

      网友评论

        本文标题:SpringBoot环境中使用MyBatis代码生成工具

        本文链接:https://www.haomeiwen.com/subject/fomcfctx.html