mybatis generator cmd 终端命令 生成dao model mapper

本文介绍如何通过MyBatis Generator自动生成持久层代码,包括配置文件详解及命令行执行步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.准备需要的jar包:mybatis-generator-core-1.3.2.jar、 ojdbc.jar(忽略版本号,这只是我用的jar 版本)

2.新建一个文件,命名:mybatisGenerator.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="F:/software/mybatisGenerator/ojdbc6.jar"/>
    <context id="my" targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressDate" value="false"/>
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>

        <!-- 数据库链接URL、用户名、密码 -->  
        <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"
                        connectionURL="jdbc:oracle:thin:@14.215.113.76:1521:orcl" userId="zh_yx_zcsp"
                        password="zhwb"/>

        <!-- 生成模型的包名和位置 --> 
        <javaModelGenerator targetPackage="ctas.test.entity"
                            targetProject="F:/software/mybatisGenerator/src">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>

        <!-- 生成的映射文件包名和位置 -->  
        <sqlMapGenerator targetPackage="ctas.test.entity.xml"
                         targetProject="F:/software/mybatisGenerator/src">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>

        <!-- 生成DAO的包名和位置 --> 
        <javaClientGenerator targetPackage="ctas.test.mapper"
                             targetProject="F:/software/mybatisGenerator/src" type="XMLMAPPER">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>

        <!--<table tableName="T_FEE_AGTBILL" domainObjectName="FeeAgentBill"
               enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false"/>-->

        <!-- 要生成那些表(更改tableName和domainObjectName就可以)表名中别有空格,否则会报错-->  
        <table tableName="SERVICE_ITEM" domainObjectName="ServiceItem"
               enableCountByExample="true" enableUpdateByExample="true"
               enableDeleteByExample="true" enableSelectByExample="true"
               selectByExampleQueryId="true">
            <!--<columnRenamingRule searchString="^D_"
                                replaceString=""/>-->
        </table>

    </context>
</generatorConfiguration>

3.打开命令提示符,进入F:\software\mybatisGenerator,输入命令:java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值