maven 配置generatorConfig.xml 自动生成代码文件

导入自动生成文件的jar包及其链接mysql的jar包


pom.xml  添加【注意是添加在build标签里面】

<build>
        <plugins>
            <plugin>
            <!-- 配置 generator-->
           <groupId>org.mybatis.generator</groupId>
           <artifactId>mybatis-generator-maven-plugin</artifactId>
           <version>1.3.2</version>
              <configuration>
                  <!--允许移动生成的文件-->   
                <verbose>true</verbose>
                <!--允许覆盖生成的文件-->    
                <overwrite>true</overwrite>  
              </configuration>  
           </plugin>
        </plugins>

    </build>

配置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>
    <classPathEntry
      location="D:\workspace\hello\target\mysql-connector-java-5.1.30.jar" />
      
    <context id="MysqlTables" targetRuntime="MyBatis3">
        <commentGenerator>
            <!-- 是否去除自动生成的注释 true:是 : false:否 -->
            <property name="suppressAllComments" value="true" />
        </commentGenerator>
        <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
            connectionURL="jdbc:mysql://127.0.0.1:3306/数据库名称" userId="用户名"
            password="密码">
        </jdbcConnection>
        <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer true,把JDBC DECIMAL 和
            NUMERIC 类型解析为java.math.BigDecimal -->
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false" />
        </javaTypeResolver>

        <!-- targetProject:自动生成代码的位置 -->

        <!-- 实体类生成文件路径  --> 

        <javaModelGenerator targetPackage="com.example.demo.domain"
            targetProject="src\main\java">
            <!-- enableSubPackages:是否让schema作为包的后缀 -->    
            <property name="enableSubPackages" value="true" />
            <!-- 从数据库返回的值被清理前后的空格  -->   
            <property name="trimStrings" value="true" />

        </javaModelGenerator>

  <!-- mapper.xml生成文件路径  -->

扫描二维码关注公众号,回复: 27196 查看本文章

        <sqlMapGenerator targetPackage="mapper"
            targetProject="src\main\resources">
            <property name="enableSubPackages" value="true" />

        </sqlMapGenerator>

    <!-- dao生成文件路径  -->

        <javaClientGenerator type="XMLMAPPER"
            targetPackage="com.example.demo.dao" targetProject="src\main\java">
            <property name="enableSubPackages" value="true" />
        </javaClientGenerator>
        <!-- tableName:用于自动生成代码的数据库表;domainObjectName:对应于数据库表的javaBean类名 -->  
        <table schema="dispatch" tableName="数据库对应表" domainObjectName="实体类对应名称"
            enableCountByExample="false" enableUpdateByExample="false"
            enableDeleteByExample="false" enableSelectByExample="false"
            selectByExampleQueryId="false">
            <!-- 否认为驼峰命名 -->
            <property name="useActualColumnNames" value="true" />
        </table>
    </context>

</generatorConfiguration>

然后运行:点击项目run as -->run configurations...--->Goals填入mybatis-generator:generate


猜你喜欢

转载自blog.csdn.net/qq_33631927/article/details/79957981