经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 数据库/运维 » MyBatis » 查看文章
mybatis逆向工程
来源:cnblogs  作者:C_凯  时间:2018/11/13 9:48:22  对本文有异议

1.POM文件:

  1. <project xmlns="http://maven.apache.org/POM/4.0.0"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <groupId>com.hck</groupId>
  6. <artifactId>produceByTable</artifactId>
  7. <packaging>war</packaging>
  8. <version>0.0.1-SNAPSHOT</version>
  9. <name>produceByTable Maven Webapp</name>
  10. <url>http://maven.apache.org</url>
  11. <dependencies>
  12. <dependency>
  13. <groupId>junit</groupId>
  14. <artifactId>junit</artifactId>
  15. <version>3.8.1</version>
  16. <scope>test</scope>
  17. </dependency>
  18. <dependency>
  19. <groupId>org.mybatis.generator</groupId>
  20. <artifactId>mybatis-generator-core</artifactId>
  21. <version>1.3.5</version>
  22. </dependency>
  23. <dependency>
  24. <groupId>mysql</groupId>
  25. <artifactId>mysql-connector-java</artifactId>
  26. <version>5.1.47</version>
  27. </dependency>
  28. </dependencies>
  29. <build>
  30. <finalName>produceByTable</finalName>
  31. <plugins>
  32. <plugin>
  33. <groupId>org.mybatis.generator</groupId>
  34. <artifactId>mybatis-generator-maven-plugin</artifactId>
  35. <version>1.3.2</version>
  36. <configuration>
  37. <verbose>true</verbose>
  38. <overwrite>true</overwrite>
  39. </configuration>
  40. </plugin>
  41. </plugins>
  42. </build>
  43. </project>

2.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. <context id="table" targetRuntime="MyBatis3">
  7. <commentGenerator>
  8. <!-- 是否去除自动生成的注释 true:是 : false:否 这里的注释是英文的 尽量可以不要-->
  9. <property name="suppressAllComments" value="true" />
  10. </commentGenerator>
  11. <!--数据库连接的信息:驱动类、连接地址、用户名、密码 mysql的 -->
  12. <jdbcConnection driverClass="com.mysql.jdbc.Driver"
  13. connectionURL="jdbc:mysql://127.0.0.1:3306/facejoy_camp?useSSL=false"
  14. userId="root"
  15. password="123456">
  16. </jdbcConnection>
  17. <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和
  18. NUMERIC 类型解析为java.math.BigDecimal -->
  19. <javaTypeResolver>
  20. <property name="forceBigDecimals" value="false" />
  21. </javaTypeResolver>
  22.  
  23. <!-- targetProject:生成PO类的位置 -->
  24. <javaModelGenerator targetPackage="com.facejoy.camp.entity.sys"
  25. targetProject="produceByTable/src/main/java">
  26. <!-- enableSubPackages:是否让schema作为包的后缀 -->
  27. <property name="enableSubPackages" value="false" />
  28. <!-- 从数据库返回的值被清理前后的空格 清理空格-->
  29. <property name="trimStrings" value="true" />
  30. </javaModelGenerator>
  31. <!-- targetProject:mapper映射文件生成的位置 -->
  32. <sqlMapGenerator targetPackage="mybatis.sys"
  33. targetProject="produceByTable/src/main/resources">
  34. <!-- enableSubPackages:是否让schema作为包的后缀 -->
  35. <property name="enableSubPackages" value="false" />
  36. </sqlMapGenerator>
  37. <!-- targetPackage:mapper接口生成的位置 -->
  38. <javaClientGenerator type="XMLMAPPER"
  39. targetPackage="com.facejoy.camp.mapper.sys"
  40. targetProject="produceByTable/src/main/java">
  41. <!-- enableSubPackages:是否让schema作为包的后缀 -->
  42. <property name="enableSubPackages" value="false" />
  43. </javaClientGenerator>
  44. <!-- 指定数据库表 后面是不生成Example类 -->
  45. <table tableName="sys_user" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
  46. <table tableName="sys_role" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
  47. <table tableName="sys_auth" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
  48. <!-- 下面是数据库中字段与mapper中的字段不一样时 进行对应设置 -->
  49. <!-- 有些表的字段需要指定java类型
  50. <table schema="" tableName="">
  51. <columnOverride column="" javaType="" />
  52. </table> -->
  53. </context>
  54. </generatorConfiguration>

3.下载mybatis逆向工程插件  windows->marketplace 搜索mybatis 全部勾选安装完成

 

4.根据图操作即可生成

 

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号