Intellij idea Maven-generate

1. pom.xml中添加以下内容(<build><pulgins>标签可根据需要添加或删除)

<build>
  <plugins>
    <plugin>
      <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>


2.新建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
            <!--这个地址是这个jar包的地址-->

location="C:\Users\work\Desktop\mybatis-generator-core-1.3.2\lib\mysql-connector-java-5.1.25-bin.jar" />
    <context id="context1" targetRuntime="MyBatis3">
        <commentGenerator>
            <!-- 是否去除自动生成的注释 true:是 : false:否 -->
            <property name="suppressAllComments" value="true" />
        </commentGenerator>

        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/meeting"
                        userId="root" password="root" />
        <javaModelGenerator targetPackage="com.freedom.domain"
                            targetProject="src/main/java" />

        <!-- 生成映射文件的包名和位置-->
        <sqlMapGenerator targetPackage="com.freedom.mapping" targetProject="src/main/java" >
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>
        <!-- 生成DAO的包名和位置-->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.freedom.dao" targetProject="src/main/java">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>

        <table tableName="t_organization" domainObjectName="Organization"
               enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
               enableSelectByExample="false" selectByExampleQueryId="false" >
            <property name="useActualColumnNames" value="false"/>
        </table>
    </context>
</generatorConfiguration>

 

 
 
3. 在Intellij IDEA添加一个“Run运行”选项,使用maven运行mybatis-generator-maven-plugin插件 :

 

wKioL1g9BZaROSIKAAA7ere4jfU920.png 

wKioL1g9BaXicqntAABQEFqtyz4086.png 

之后弹出运行配置框,为当前配置配置一个名称,这里其名为"generator",然后在 “Command line” 选项中输入“mybatis-generator:generate  -e

这里加了“-e ”选项是为了让该插件输出详细信息,这样可以帮助我们定位问题。

wKiom1g9BbLQ4CUGAABBkjRV6bU948.png 

wKioL1g9BcbjMEuLAALGP8IeVGs105.png 

如果添加成功,则会在run 选项中有“generator” 选项,如下:

wKiom1g9BeywCWviAAAjjYc5Ca4421.png 

4.ok,大功告成