owl-mybatis-generator-core-1.4.1-SNAPSHOT.jar 使用说明

声明:
本jar基于开源项目 mybatis-generator 源码开发

使用本jar生成的xml为mysql 的sql 代码。出于各种原因,本jar几乎重写了xml中的全部sql
使用本jar数据库表需要有且只有唯一id,关系数据表除外
使用本jar,数据库表中最好不要出现超大字段。如果有超大字段的需要,建议将其存入文件并在数据库中保留路径

使用方法(基本同 mybatis-generator ,额外添加了几个配置参数,详见本包中的xml):
1. 更新 generatorconfig.xml 配置信息,设置数据库驱动
2. 可选生成基类基于swagger的注释开启
3. 设置数据库地址、账号和密码信息
4. 设置各种模型的包名和位置信息。即修改 targetPackage
5. 设置表名和对应实体信息,设置是否开启关系表模式,如果设置为关系表还需要设置关系主id和关系跟随id,关系表可以不设置唯一id。其他表需要设置唯一id
6. 在本层目录打开命令行,执行 Java -jar owl-mybatis-generator-core-1.4.1-SNAPSHOT.jar -configfile generatorConfig.xml -overwrite


本jar额外提供:
1:自动生成 controller 、service和dao,以上三个基于继承实现,公共方法均已经被提入公网jar,controller 自动注入service,而service将会自动注入dao。非关系表的 service 和 dao,mapper除了基础的增删改查,额外提供批量插入,批量删除,模糊查询,精确查询,以及分页查询,全量获取等功能,并均已实现。
2:model自动添加mysql中的表注释和字段注释
3:controller 自动生成代码,并实现增删改查基础功能,当存在布尔值的status类型时,自动生成逻辑删除功能代码。当存在布尔值hasBan类型时,自动生成启用和禁用代码。使用这两个属性并期望生效时,你可能还需要更改查询方法,并将该属性设置为true,以便通知底层查询条件已经变更
4:提供创建日期查询区间功能。list查询时,如果对象存在createTime字段,并传入startTime和endTime即可开启。传入格式为:"yyyy-MM-dd HH:mm:ss"
5:service 和 dao 额外 添加关系表支持,并提供关系表的增删查,批量插入,批量删除,批量更新,并均已实现,部分数据操作涉及失败回滚,已经添加默认注解回滚
6: 提供swagger支持(开启后,实体类直接生成含有注释的对象,controller自动添加表注释和默认方法注释)


注:
    1. 使用本jar,需要保证当前目录存在 src 目录
    2. 请注意,自动生成代码正确的前提是除设置为关系表外的表具有唯一主键。
    3. 本jar生成的controller全部使用post,所有参数均通过requestbody获取,controller会自动添加跨域支持
    4. 不开启swagger时,update参数检查默认使用OwlCheckParams注解

由于mvc模块已被单独拆出,所以使用本包需使 mvc jar来提供衔接
github地址 https://github.com/engwen/owlMagicComment,
也可以直接添加公网 maven 引用
<!-- https://mvnrepository.com/artifact/com.github.engwen/owlMagicComment -->
<dependency>
    <groupId>com.github.engwen</groupId>
    <artifactId>owlMagicComment</artifactId>
    <version>3.0.2</version>
</dependency>

 

含有删除标识时,自动生成逻辑删除和物理删除代码

含有启用字段时自动生成启用、禁用功能

自动加载注释(不启用swagger)

补足批量功能:

附 generatorConfig.xml 配置文件内容:

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration  
  PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"  
  "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">  

<!-- 数据库驱动-->  
<generatorConfiguration>  
<!-- 数据库驱动-->
    <classPathEntry  location="mysql-connector-java-5.1.25-bin.jar"/>
    <context id="DB2Tables"  targetRuntime="MyBatis3">
        <property name="javaFileEncoding" value="UTF-8"/>
        <commentGenerator>
            <property name="suppressDate" value="false"/>  
            <!-- 是否去除自动生成的注释 true:是 : false:否 -->  
            <property name="suppressAllComments" value="true"/>  
            <!--额外添加配置 是否生成基类基于swagger的注释 true:是 : false:否 -->  
            <property name="suppressSwagger" value="false"/>  
        </commentGenerator>  
        <!--数据库链接URL,用户名、密码 -->  
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/db_shiro_prod" userId="root" password="000000">        
        </jdbcConnection>  
        <javaTypeResolver>  
            <property name="forceBigDecimals" value="false"/>  
        </javaTypeResolver>  
        <!-- 生成模型的包名和位置-->  
        <javaModelGenerator targetPackage="com.owl.auth.model" targetProject="src">  
            <property name="enableSubPackages" value="true"/>  
            <property name="trimStrings" value="true"/>  
        </javaModelGenerator>
        <!-- 生成mapper映射文件的包名和位置--> 
        <sqlMapGenerator targetPackage="mapping" targetProject="src">  
            <property name="enableSubPackages" value="true"/>  
        </sqlMapGenerator>  
        <!-- 生成dao的包名和位置--> 
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.owl.auth.dao" targetProject="src">  
            <property name="enableSubPackages" value="true"/>  
        </javaClientGenerator>
        <!-- 额外添加配置 生成service的包名和位置--> 
        <javaServiceGenerator targetPackage="com.owl.auth.service" targetProject="src">  
            <property name="enableSubPackages" value="true"/>  
            <property name="trimStrings" value="true"/>
        </javaServiceGenerator>  
        <!-- 额外添加配置 生成controller的包名和位置-->
        <javaControllerGenerator targetPackage="com.owl.auth.controller" targetProject="src">  
            <property name="enableSubPackages" value="true"/>  
            <property name="trimStrings" value="true"/>  
        </javaControllerGenerator>  
          
    <!-- 关于主表: 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名,除关系表外,其他表必须存在唯一主键
        当主表存在 status 字段并且为 tinyint 类型字段时,将会自动生成 逻辑删除代码
        当主表存在 has_ban 字段并且为 tinyint 类型字段时,将会自动生成 启用禁用相关代码
    -->
    <!-- 关于关系表:关系表可以不设置唯一主键,如果想使用中间表生成工具生成中间表的插入、删除等sql,请设置中间表支持参数 isRelation="true" 设置主表id mainIdName="主表id名称" 和从表 followerIdName="从表id名称"
         依据实际需要设置是否包含其他属性 hasOtherPro="false" or "true",当为true 存在其他属性时,系统会自动略过一些方法
         生成工具将会自动生成 单项插入,批量插入,单项删除,批量删除,批量更新和查询代码。如果中间表不想使用中间生成工具,依旧可以使用默认代码生成,但此时表中必须存在唯一主键
    --> 
    <table tableName="owl_org" domainObjectName="OwlOrg" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
    </table>
    <table tableName="owl_user" domainObjectName="OwlUser" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
    </table>
    <table tableName="owl_menu" domainObjectName="OwlMenu" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
    </table>
    <table tableName="owl_permission" domainObjectName="OwlPermission" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
    </table>
    <table tableName="owl_role" domainObjectName="OwlRole" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
    </table>
    <table tableName="owl_org_user" domainObjectName="OwlOrgUser" isRelation="true" mainIdName="org_code" followerIdName="user_account" hasOtherPro="true"
    enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
    </table>
    <table tableName="owl_role_menu" domainObjectName="OwlRoleMenu"  isRelation="true" mainIdName="role_code" followerIdName="menu_code" hasOtherPro="true"
    enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
    </table>
    <table tableName="owl_user_role" domainObjectName="OwlUserRole" isRelation="true" mainIdName="user_account" followerIdName="role_code"   hasOtherPro="true"
    enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
    </table>
    <table tableName="owl_role_permission" domainObjectName="OwlRolePermission" isRelation="true" mainIdName="role_id" followerIdName="permission_id"   hasOtherPro="true"
    enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
    </table>
    <table tableName="owl_apply" domainObjectName="OwlApply" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
    </table>
    <table tableName="owl_dict" domainObjectName="OwlDict" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
    </table>

</context>  
</generatorConfiguration>  
 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值