zoukankan      html  css  js  c++  java
  • mybatis-generator使用

    mybatis-generate使用

    第一步导入依赖

     <plugin>
            <!--Mybatis-generator插件,用于自动生成Mapper和POJO-->
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-maven-plugin</artifactId>
            <version>1.3.2</version>
            <configuration>
              <!--配置文件的位置-->
              <configurationFile>src/main/resources/mybatis-generator-config.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>
    

    第二步配置 mybatis-generator-config.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>
    
      <!-- 本地数据库驱动程序jar包的全路径 -->
      <classPathEntry
        location="D:
    epomysqlmysql-connector-java5.1.47mysql-connector-java-5.1.47.jar"/>
    
      <context id="context" targetRuntime="MyBatis3">
        <commentGenerator>
          <property name="suppressAllComments" value="false"/>
          <property name="suppressDate" value="true"/>
        </commentGenerator>
    
        <!-- 数据库的相关配置 -->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
          connectionURL="jdbc:mysql://xxxx"
          userId="root"
          password="xxxx"/>
    
        <javaTypeResolver>
          <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>
    
        <!-- 实体类生成的位置 -->
        <javaModelGenerator targetPackage="com.xxx" targetProject="src/main/resources">
        <property name="enableSubPackages" value="false"/>
        <property name="trimStrings" value="true"/>
        </javaModelGenerator>
    
        <!-- *Mapper.xml 文件的位置 -->
        <sqlMapGenerator targetPackage="com.xxx"
          targetProject="src/main/resources">
          <property name="material" value="false"/>
        </sqlMapGenerator>
    
        <!-- Mapper 接口文件的位置 -->
        <javaClientGenerator targetPackage="com.xxxx"
          targetProject="src/main/resources" type="XMLMAPPER">
          <property name="material" value="false"/>
        </javaClientGenerator>
    
        <!-- 相关表的配置 -->
        <!--<table tableName="db_xxx" enableCountByExample="false"-->
          <!--enableDeleteByExample="false"-->
          <!--enableSelectByExample="false"-->
          <!--enableUpdateByExample="false">-->
    
          <table tableName="db_shop.tbl_shop_wechat_advertorial"
            domainObjectName="material"
            enableCountByExample="false"
            enableUpdateByExample="false"
            enableDeleteByExample="false"
            enableSelectByExample="false"
            selectByExampleQueryId="false">
        </table>
      </context>
    </generatorConfiguration>
    

    第三步 使用插件编译

    第四步 保持表中字段命名方式

    <property name="useActualColumnNames" value="true" />
    
    
  • 相关阅读:
    2020年4月4日训练
    HZNU Training 17 for Zhejiang Provincial Competition 2020
    [kuangbin带你飞]专题四 最短路练习
    三分法
    洛谷多校第一周续
    洛谷春季 ACM 多校训练第五周
    简单数学三月小结
    线段树&树状数组
    图论三月小结
    Java中Double保留后小数位的几种方法
  • 原文地址:https://www.cnblogs.com/MagicalFool/p/10195196.html
Copyright © 2011-2022 走看看