zoukankan      html  css  js  c++  java
  • 【Java MyBatis Generator】使用generator自动生成Dao,Mapping和实体文件

    具体请参照:

    http://blog.csdn.net/fengshizty/article/details/43086833

    按照上面博客地址,下载Generator的依赖包:

    如下是我的配置文件:

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
     3 <generatorConfiguration>
     4     <!-- 数据库驱动包位置 -->
     5     <classPathEntry location="C:Generategeneratorgeneratormysql-connector-java-5.1.34.jar" /> 
     6     <!-- <classPathEntry location="C:oracleproduct10.2.0db_1jdbclibojdbc14.jar" />-->
     7     <context id="DB2Tables" targetRuntime="MyBatis3">
     8         <commentGenerator>
     9             <property name="suppressAllComments" value="true" />
    10         </commentGenerator>
    11         <!-- 数据库链接URL、用户名、密码 -->
    12          <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/testmybatis" userId="root" password="XXXXX"> 
    13         <!--<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@localhost:1521:orcl" userId="msa" password="msa">-->
    14         </jdbcConnection>
    15         <javaTypeResolver>
    16             <property name="forceBigDecimals" value="false" />
    17         </javaTypeResolver>
    18         <!-- 生成模型的包名和位置 -->
    19         <javaModelGenerator targetPackage="com.zlg.model" targetProject="C:Generategeneratorgeneratorsrc">
    20             <property name="enableSubPackages" value="true" />
    21             <property name="trimStrings" value="true" />
    22         </javaModelGenerator>
    23         <!-- 生成的映射文件包名和位置 -->
    24         <sqlMapGenerator targetPackage="com.zlg.mapping" targetProject="C:Generategeneratorgeneratorsrc">
    25             <property name="enableSubPackages" value="true" />
    26         </sqlMapGenerator>
    27         <!-- 生成DAO的包名和位置 -->
    28         <javaClientGenerator type="XMLMAPPER" targetPackage="com.zlg.dao" targetProject="C:Generategeneratorgeneratorsrc">
    29             <property name="enableSubPackages" value="true" />
    30         </javaClientGenerator>
    31         <!-- 要生成那些表(更改tableName和domainObjectName就可以) -->
    32         <table tableName="user" domainObjectName="UserInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
    33         <table tableName="dept" domainObjectName="DeptInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
    34         <table tableName="emp" domainObjectName="EmpInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
    35         <table tableName="cost" domainObjectName="CostInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
    36     </context>
    37 </generatorConfiguration>
    View Code

    根据以上配置文件中的标记位置,修改成你需要的位置,然后运行如下指令(记住用tab键补全命令,这个用过CMD或者Linux都知道)。

    运行成功后,就生成了如下文件:

    当然,如果你比较懒,可以直接把生成路径设置成你项目的相应位置。

    此时,你就可以把这些对应的文件拷贝到项目的相关位置了。非常简单,而且以上链接的作者已经写得很详细了。

    感谢分享~

  • 相关阅读:
    TWaver中文社区 » 关于
    RedMon Redirection Port Monitor
    dust good
    HiSpider(Hitask) is a fast and high performance spider with high speed
    42qu.com 找到给你答案的人
    yet another 牛人
    Simple Map Reduce at home
    China (googlegroups) [CPyUG:78205] 基于Python的MapReduce算法的快速构建框架
    retools 0.1 : Python Package Index
    Bloomfilter 的应用场景 黄刚的专栏 博客频道 CSDN.NET
  • 原文地址:https://www.cnblogs.com/flydkPocketMagic/p/5998478.html
Copyright © 2011-2022 走看看