第一步:

需要两个jar包(aymsp-alipay下备份):

  • mybatis-generator-core-1.4.0.jar
  • mysql-connector-java-5.1.31.jar (数据库驱动)

第二步:

配置 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. <!--MySQL连接驱动-->
  7. <classPathEntry location="mysql-connector-java-5.1.31.jar" />
  8. <!--数据库链接URL,用户名、密码 -->
  9. <context id="MySQL" targetRuntime="MyBatis3">
  10. <commentGenerator>
  11. <property name="suppressDate" value="true"/>
  12. <!-- 是否去除自动生成的注释 true:是 : false:否 -->
  13. <property name="suppressAllComments" value="true"/>
  14. </commentGenerator>
  15. <!----------------- 第一个需要修改的地方 ----------------->
  16. <jdbcConnection driverClass="com.mysql.jdbc.Driver"
  17. connectionURL="jdbc:mysql://localhost:3306/aymspdb"
  18. userId="root"
  19. password="pass">
  20. </jdbcConnection>
  21. <!--是否启用java.math.BigDecimal-->
  22. <javaTypeResolver >
  23. <property name="forceBigDecimals" value="false" />
  24. </javaTypeResolver>
  25. <!----------------- 第二个需要修改的地方 ----------------->
  26. <!-- 生成模型的包名和位置-->
  27. <javaModelGenerator targetPackage="org.ayfoundation.api.impl.app.alipay.entity.model" targetProject="output">
  28. <property name="enableSubPackages" value="true" />
  29. <property name="trimStrings" value="true" />
  30. </javaModelGenerator>
  31. <!----------------- 第三个需要修改的地方 ----------------->
  32. <!-- 生成映射文件的包名和位置-->
  33. <sqlMapGenerator targetPackage="test.xml" targetProject="output">
  34. <property name="enableSubPackages" value="true" />
  35. </sqlMapGenerator>
  36. <!----------------- 第四个需要修改的地方 ----------------->
  37. <!-- 生成DAO的包名和位置-->
  38. <javaClientGenerator type="XMLMAPPER" targetPackage="org.ayfoundation.api.impl.app.alipay.entity.dao" targetProject="output">
  39. <property name="enableSubPackages" value="true" />
  40. </javaClientGenerator>
  41. <!----------------- 第五个需要修改的地方 ----------------->
  42. <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->
  43. <table tableName="app_alipay_downloadbill" domainObjectName="AlipayBillInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="true" selectByExampleQueryId="true">
  44. </table>
  45. </context>
  46. </generatorConfiguration>

第三步:

java -jar mybatis-generator-core-1.3.5.jar -configfile generatorConfig.xml