idea整合mybatis generator

1、引入插件 pom.xml

<plugin>
   <groupId>org.mybatis.generator</groupId>
   <artifactId>mybatis-generator-maven-plugin</artifactId>
   <version>1.3.2</version>
   <configuration>
      <!--配置文件的位置-->
      <configurationFile>src/main/resources/generatorConfig.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>

2、创建generatorConfig.xml文件 文件地址src/main/resources

<?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:\Works\WorkMessage\sqljdbc42.jar" />
    <context id="DB2Tables" targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressDate" value="true" />
            <!-- 是否去除自动生成的注释 true:是 : false:否 -->
            <property name="suppressAllComments" value="true" />
        </commentGenerator>
        <!--数据库链接URL,用户名、密码 -->
        <jdbcConnection
            driverClass="com.microsoft.sqlserver.jdbc.SQLServerDriver"
            connectionURL="jdbc:sqlserver://localhost:1433;DatabaseName=b2b_platform"
            userId="sa" password="Xbb05617976539">
        </jdbcConnection>
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false" />
        </javaTypeResolver>
        <!-- 生成模型的包名和位置 -->
        <javaModelGenerator
            targetPackage="com.seeforesee.c4c.product.entity.dto"
            targetProject="b2b/src/main/java">
            <property name="enableSubPackages" value="true" />
            <property name="trimStrings" value="true" />
        </javaModelGenerator>
        <!-- 生成映射文件的包名和位置 -->
        <sqlMapGenerator
            targetPackage="com.seeforesee.c4c.product.repository"
            targetProject="b2b/src/main/resources">
            <property name="enableSubPackages" value="true" />
        </sqlMapGenerator>
        <!-- 生成DAO的包名和位置 -->
        <javaClientGenerator type="XMLMAPPER"
            targetPackage="com.seeforesee.c4c.product.repository"
            targetProject="b2b/src/main/java">
            <property name="enableSubPackages" value="true" />
        </javaClientGenerator>
        <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名 customer 客户信息表 -->
    <!--      <table tableName="customer" domainObjectName="Customer" enableCountByExample="false" 
            enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" 
            selectByExampleQueryId="false"></table>  -->
            
            <table tableName="distributor_customer_sales_month_client" 
            domainObjectName="distributorCustomerSalesMonthClient" enableCountByExample="false" enableUpdateByExample="false" 
            enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
 

    </context>
</generatorConfiguration>

3、运行插件

1)采用maven自己生生的任务栏执行,如图

2)采用自行定义maven任务栏,maven----》生成新的插件   

command line:mybatis-generator:generate -e

猜你喜欢

转载自blog.csdn.net/baobaodehao1991/article/details/82147453
今日推荐