mybatis-generator逆向工程设置不生成Example类

avatar 2017年09月09日12:02:48 1 9486 views
博主分享免费Java教学视频,B站账号:Java刘哥
之前每次生成 po 和 mapper,都会生成 Example 类和其对应的 CURD方法。删起来也比较麻烦,所以干脆让它不生成即可。 具体配置很简单,只需要在要设置的表的 table 标签里将要生成的方法给关掉即可,代码如下。
  1. <table tableName="user"
  2.         enableCountByExample="false"
  3.         enableUpdateByExample="false"
  4.         enableDeleteByExample="false"
  5.         enableSelectByExample="false"
  6.         selectByExampleQueryId="false">
  7. </table>
最后附上完整的 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="testTables" targetRuntime="MyBatis3">
  7.         <commentGenerator>
  8.             <!-- 是否去除自动生成的注释 true:是 : false:否 -->
  9.             <property name="suppressAllComments" value="true" />
  10.         </commentGenerator>
  11.         <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
  12.         <jdbcConnection driverClass="com.mysql.jdbc.Driver"
  13.                         connectionURL="jdbc:mysql://localhost:3306/forest_blog?tinyInt1isBit=false" userId="root"
  14.                         password="">
  15.         </jdbcConnection>
  16.         <javaTypeResolver>
  17.             <property name="forceBigDecimals" value="false" />
  18.         </javaTypeResolver>
  19.         <!-- targetProject:生成PO类的位置,重要!! -->
  20.         <javaModelGenerator targetPackage="com.liuyanzhao.blog.po"
  21.                             targetProject="myGenerator/src">
  22.             <!-- enableSubPackages:是否让schema作为包的后缀 -->
  23.             <property name="enableSubPackages" value="false" />
  24.             <!-- 从数据库返回的值被清理前后的空格 -->
  25.             <property name="trimStrings" value="true" />
  26.         </javaModelGenerator>
  27.         <!-- targetProject:mapper映射文件生成的位置,重要!! -->
  28.         <sqlMapGenerator targetPackage="com.liuyanzhao.blog.mapper"
  29.                          targetProject="myGenerator/src">
  30.             <property name="enableSubPackages" value="false" />
  31.         </sqlMapGenerator>
  32.         <!-- targetPackage:mapper接口生成的位置,重要!! -->
  33.         <javaClientGenerator type="XMLMAPPER"
  34.                              targetPackage="com.liuyanzhao.blog.mapper"
  35.                              targetProject="myGenerator/src">
  36.             <property name="enableSubPackages" value="false" />
  37.         </javaClientGenerator>
  38.         <!-- 指定数据库表,要生成哪些表,就写哪些表,要和数据库中对应,不能写错! -->
  39.         <table tableName="user"
  40.             enableCountByExample="false"
  41.             enableUpdateByExample="false"
  42.             enableDeleteByExample="false"
  43.             enableSelectByExample="false"
  44.             selectByExampleQueryId="false">
  45.         </table>
  46.         <table tableName="article"
  47.             enableCountByExample="false"
  48.             enableUpdateByExample="false"
  49.             enableDeleteByExample="false"
  50.             enableSelectByExample="false"
  51.             selectByExampleQueryId="false">
  52.         </table>
  53.     </context>
  54. </generatorConfiguration>
 

更多文章:mybatis逆向工程利用mybatis-generator-core自动生成代码

本文链接:https://liuyanzhao.com/6207.html

  • 微信
  • 交流学习,有偿服务
  • weinxin
  • 博客/Java交流群
  • 资源分享,问题解决,技术交流。群号:590480292
  • weinxin
avatar

发表评论

avatar 登录者:匿名
匿名评论,评论回复后会有邮件通知

  

已通过评论:0   待审核评论数:0