1、pom.xml文件增加插件节点:

<plugin>
    <groupId>org.mybatis.generator</groupId>
    <artifactId>mybatis-generator-maven-plugin</artifactId>
    <version>1.3.5</version>
    <configuration>
        <verbose>true</verbose>
        <overwrite>true</overwrite>
    </configuration>
</plugin>

2、resources/generatorConfig.xml文件配置:
一、jdbc连接库:mysql-connector-java-5.1.30.jar
二、数据库地址:jdbc:mysql://172.25.128.1:3306/chhospital

<?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="C:/Users/liaocs/.m2/repository/mysql/mysql-connector-java/5.1.30/mysql-connector-java-5.1.30.jar" />
   <context id="mysqlcontext" targetRuntime="MyBatis3" defaultModelType="flat">
      <property name="beginningDelimiter" value="`" />
      <property name="endingDelimiter" value="`" />

      <commentGenerator>
         <property name="suppressDate" value="true" />
         <property name="suppressAllComments" value="true" />
      </commentGenerator>

      <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://172.25.128.1:3306/chhospital" userId="root" password="123456">
      </jdbcConnection>

      <javaModelGenerator targetPackage="com.an.chhospatil.model" targetProject="src/main/java">
         <property name="trimStrings" value="true" />
      </javaModelGenerator>

      <sqlMapGenerator targetPackage="com.an.chhospatil.mapping" targetProject="src/main/java" />

      <javaClientGenerator targetPackage="com.an.chhospatil.dao" targetProject="src/main/java" type="XMLMAPPER" />

      <table schema="chhospital" tableName="testlcs"
         enableCountByExample="false" enableUpdateByExample="true"
         enableDeleteByExample="true" enableSelectByExample="true"
         selectByExampleQueryId="true">
      </table>
   </context>
</generatorConfiguration>
3、配置

Step1:选择配置edit configuration

Step2:创建maven运行项

IntelliJ 使用 MyBatis Generator 详解

Step3:配置命令 mybatis-generator:generate -e

IntelliJ 使用 MyBatis Generator 详解

Step4:运行

IntelliJ 使用 MyBatis Generator 详解
做完以上几步。就可以看到运行的选项。点击运行即可。



相关文章: