代码地址: https://gitee.com/zjj19941/MybatisGenerated

在idea中集成了MyBatis Generator的功能,下面介绍需要怎么使用这个插件。

1、在pom.xml文件的build节点加上以下代码

  1. <plugin>
  2. <groupId>org.mybatis.generator</groupId>
  3. <artifactId>mybatis-generator-maven-plugin</artifactId>
  4. <version>1.3.5</version>
  5. <configuration>
  6. <configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
  7. <overwrite>true</overwrite>
  8. <verbose>true</verbose>
  9. </configuration>
  10. </plugin>

2、在resources目录下新建generatorConfig.xml文件,内容如下:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE generatorConfiguration
  3. PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
  4. "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
  5. <generatorConfiguration>
  6. <classPathEntry location="C:\splanchnic\maven\mvnRespo\mysql\mysql-
  7. connector-java\5.1.44\mysql-connector-java-5.1.44.jar" />
  8. <context id="testTables" targetRuntime="MyBatis3">
  9. <commentGenerator>
  10. <property name="suppressAllComments" value="true" />
  11. </commentGenerator>
  12. <jdbcConnection driverClass="com.mysql.jdbc.Driver"
  13. connectionURL="jdbc:mysql://localhost:3306/angus_oa"
  14. userId="root"
  15. password="123456">
  16. </jdbcConnection>
  17. <javaTypeResolver>
  18. <property name="forceBigDecimals" value="false" />
  19. </javaTypeResolver>
  20. <javaModelGenerator targetPackage="com.angus.entity"
  21. targetProject="src/main/java">
  22. <property name="enableSubPackages" value="false" />
  23. <property name="trimStrings" value="true" />
  24. </javaModelGenerator>
  25. <sqlMapGenerator targetPackage="main.resources.mapping"
  26. targetProject="src">
  27. <property name="enableSubPackages" value="false" />
  28. </sqlMapGenerator>
  29. <javaClientGenerator type="XMLMAPPER"
  30. targetPackage="com.angus.dao"
  31. targetProject="src/main/java">
  32. <property name="enableSubPackages" value="false" />
  33. </javaClientGenerator>
  34. <table tableName="t_user" domainObjectName="User"
  35. enableCountByExample="false" enableUpdateByExample="false"
  36. enableDeleteByExample="false" enableSelectByExample="false"
  37. selectByExampleQueryId="false"></table>
  38. </context>
  39. </generatorConfiguration>

注意修改 这块儿的配置信息,修改成自己的账号密码

connectionURL=”jdbc:mysql://localhost:3306/angus_oa”
userId=”root”
password=”123456”>

3、加入maven配置,在Command line中加入mybatis-generator:generate -e,效果如下:

Mybatis逆向工程代码 - 图1

mybatis-generator:generate -e

4、最后,启动项目即可

Mybatis逆向工程代码 - 图2