[关闭]
@wxf 2017-06-03T16:40:53.000000Z 字数 1785 阅读 626

MyBati逆向工程

项目实战


MyBatis逆向工程就是根据数据表生成java代码。搭建逆向工程的步骤如下所示:

  1. 在mapper子模块中添加generatorConfig.xml配置文件。配置文件的详细介绍:
  1. <generatorConfiguration>
  2. <!--指定特定数据库的jdbc驱动jar包的位置-->
  3. <classPathEntry location="D:\Maven\resource\mysql\mysql-connector-java\5.1.32\mysql-connector-java-5.1.32.jar"/>
  4. <context id="testTables" targetRuntime="MyBatis3">
  5. <commentGenerator> <!-- 是否去除自动生成的注释 -->
  6. <property name="suppressAllComments" value="true" />
  7. </commentGenerator>
  8. <jdbcConnection
  9. driverClass="com.mysql.jdbc.Driver"
  10. connectionURL="jdbc:mysql://localhost:3306/mmall"
  11. userId="root"
  12. password="123456"
  13. > <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
  14. </jdbcConnection>
  15. <!--
  16. 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,
  17. 为true时把JDBC DECIMAL 和 NUMERIC类型解析为BigDecimal
  18. -->
  19. <javaTypeResolver>
  20. <property name="forceBigDecimals" value="false" />
  21. </javaTypeResolver>
  22. <!-- targetProject:生成POJO类的位置 -->
  23. <javaModelGenerator targetPackage="com.wxf.pojo" targetProject=".\src\main\java">
  24. <property name="enableSubPackages" value="false" />
  25. <property name="trimStrings" value="true" />
  26. </javaModelGenerator>
  27. <!-- targetProject:mapper映射文件生成的位置 -->
  28. <sqlMapGenerator targetPackage="com.wxf.persist" targetProject=".\src\main\resources">
  29. <property name="enableSubPackages" value="false" />
  30. </sqlMapGenerator>
  31. <!-- targetPackage:mapper接口生成的位置 -->
  32. <javaClientGenerator type="XMLMAPPER" targetPackage="com.wxf.persist" targetProject=".\src\main\java">
  33. <property name="enableSubPackages" value="false" />
  34. </javaClientGenerator>
  35. <!-- 指定数据库表 -->
  36. <table tableName="mmall_product"
  37. domainObjectName="Product"
  38. enableCountByExample="false"
  39. enableUpdateByExample="false"
  40. enableDeleteByExample="false"
  41. enableSelectByExample="false"
  42. selectByExampleQueryId="false">
  43. <columnOverride column="detail" jdbcType="VARCHAR" />
  44. <columnOverride column="sub_images" jdbcType="VARCHAR" />
  45. </table>
  46. </context>
  47. </generatorConfiguration>

 
2. 列表项
在Maven Projects中找到mybatis-generator,双击执行。
image_1bhnc833e3ro13klj5l16nv1bop9.png-50.2kB

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注