mybatis自动生成SQL,外部终端生成

jar准备,连接驱动与生成jar

 

只需要这两个jar的原因很简单,MySQL驱动直接去探测库,生成jar直接拼接生成对应的SQL即可。一个是探测一个去生成。就2个jar就够了

 

外部生成不同于maven配置,需要手动指定MySQL驱动jar在哪里

 

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="D:\Ggenerator\mysql-connector-java-5.1.34.jar" />

    <context id="mysqlTables" targetRuntime="MyBatis3">
        <!--数据源配置-->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql:///web_test?characterEncoding=utf-8"
                        userId="root"
                        password=""/>
        <!--指定生成的类型为java类型,避免数据库中number等类型字段 -->
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>

        <!--自动生成的实体的存放包路径 类 -->
        <javaModelGenerator targetPackage="com.kaige123.daomu.dao"
                            targetProject="D:\Ggenerator\src\main\java">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>

        <!--自动生成的*Mapper.xml文件存放路径 -->
        <sqlMapGenerator targetPackage="com.kaige123.daomu.dao"
                         targetProject="D:\Ggenerator\src\main\resources">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>

        <!--自动生成的*Mapper.java存放路径 接口 -->
        <javaClientGenerator type="XMLMAPPER"
                             targetPackage="com.kaige123.daomu.dao"
                             targetProject="D:\Ggenerator\src\main\java">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>

        <!--table表格的配置
        tableName表格名称 domainObjectName实例名称 Example是否生成表达式-->
        <table tableName="test01" domainObjectName="test01Table"
               enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false">
        </table>

        <table tableName="log" domainObjectName="logTable"
               enableCountByExample="true" enableUpdateByExample="true"
               enableDeleteByExample="true" enableSelectByExample="true"
               selectByExampleQueryId="true">
        </table>
    </context>

</generatorConfiguration>

 

准备包,如果包不存在,则包找不到包错误,生成肯定是没有文件了

 

运行jar,jar传命令:

java -jar D:\Ggenerator\mybatis-generator-core-1.3.5.jar -configfile D:\Ggenerator\generatorConfig.xml -overwrite

pause

 

在Windows运行的,pause让终端处于暂停状态,否则运行后一闪而过,结果是什么都不知道。

传递参数为生成config.xml在哪里,-o应该是按照指定的位置去输出

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值