倾城哥哥123的gravatar头像
倾城哥哥123 2018-10-22 11:30:10
mybatis逆向工程生成代码步骤

一、需要的文件

1、generator.xml 配置文件 (修改代码中自己所放jar包路径、数据库链接地址,用户名、密码,以及需要生成文件对应的表名)
2、mybatis-generator-core-1.3.2.jar 生成代码所需jar包
3、sqljdbc4.jar  数据库驱动jar
二、操作步骤:1、打开命令提示符,进入generator.xml所在文件夹
      2、输入命令:java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite
      3、出现Mybatis Generator finished successfully 代码生成完成

三、genrator.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="G:\generator\ojdbc7.jar" /> -->
    <classPathEntry location="E:\generator\mysql-connector-java-5.1.41-bin.jar" />
    <!-- <classPathEntry location="G:\oracle\product\10.2.0\db_1\jdbc\lib\ojdbc14.jar" />-->  
    <context id="DB2Tables" targetRuntime="MyBatis3">  
        <commentGenerator>  
            <property name="suppressAllComments" value="true" />  
        </commentGenerator>  
        <!-- 数据库链接URL、用户名、密码 -->  
         <!--<jdbcConnection driverClass="com.microsoft.sqlserver.jdbc.SQLServerDriver" connectionURL="jdbc:sqlserver://61.163.210.30;DatabaseName=zih_db7 " userId="Sz7i1h8P" password="ZZLGRoeisi122hjb718">  --> 
         <!--<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@192.168.19.132:1521:orcl" userId="test" password="test"> -->
         <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/o2o" userId="root" password="root"> 
        </jdbcConnection>  
        <javaTypeResolver>  
            <property name="forceBigDecimals" value="false" />  
        </javaTypeResolver>  
        <!-- 生成模型的包名和位置 -->  
        <javaModelGenerator targetPackage="com.taotao.pojo" targetProject="E:\generator\src">  
            <property name="enableSubPackages" value="true" />  
            <property name="trimStrings" value="true" />  
        </javaModelGenerator>  
        <!-- 生成的映射文件包名和位置 -->  
        <sqlMapGenerator targetPackage="com.taotao.mapper" targetProject="E:\generator\src">  
            <property name="enableSubPackages" value="true" />  
        </sqlMapGenerator>  
        <!-- 生成DAO的包名和位置 -->  
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.taotao.mapper" targetProject="E:\generator\src">  
            <property name="enableSubPackages" value="true" />  
        </javaClientGenerator>  
        <!-- 要生成那些表(更改tableName和domainObjectName就可以) -->  
        <!--
        <table tableName="SITE_INFO" domainObjectName="SiteInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />     
        -->        
        <table tableName="message" domainObjectName="Message" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
    </context>  
</generatorConfiguration>  

 


打赏
最近浏览
小旭风干迷茫  LV1 2021年1月15日
2602678357  LV1 2020年6月17日
静默编程 2020年5月19日
暂无贡献等级
zhuanqianyangxibei 2020年5月13日
暂无贡献等级
2583749636 2019年12月26日
暂无贡献等级
zkjhrd01 2019年12月25日
暂无贡献等级
pvcall  LV2 2019年11月20日
goodcs  LV7 2019年11月13日
xjydcm  LV2 2019年7月29日
开发小菜阿邪  LV1 2019年6月14日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友