码迷,mamicode.com
首页 > 其他好文 > 详细

【MyBatis】逆向工程

时间:2017-09-07 15:03:01      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:ssd   false   word   let   select   enc   branch   注释   1.3   

准备jar包:

mybatis-3.4.1.jar
mybatis-generator-core-1.3.5.jar
mysql-connector-java-3.1.10-bin.jar

************************************************JAVA代码********************************************

  List<String> warnings = new ArrayList<String>();
     boolean overwrite = true;
     File configFile = new File("src/mbg.xml");
     ConfigurationParser cp = new ConfigurationParser(warnings);
     Configuration config = cp.parseConfiguration(configFile);
     DefaultShellCallback callback = new DefaultShellCallback(overwrite);
     MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
     myBatisGenerator.generate(null);

************************************************配置文件**********************************************

<?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-3.1.10-bin.jar"/>   -->
    <context id="DB2Tables"  targetRuntime="MyBatis3"> 
        <commentGenerator> 
            <property name="suppressDate" value="true"/> 
            <!-- 是否去除自动生成的注释 true:是 : false:否 --> 
            <property name="suppressAllComments" value="true"/> 
        </commentGenerator> 
        <!--数据库链接URL,用户名、密码 --> 
        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/myoffice" userId="root" password="root"> 
        </jdbcConnection> 
        <javaTypeResolver> 
            <property name="forceBigDecimals" value="false"/> 
        </javaTypeResolver> 
        <!-- 生成模型entity的包名和位置--> 
        <javaModelGenerator targetPackage="entity" targetProject=".\src"> 
            <property name="enableSubPackages" value="true"/> 
            <property name="trimStrings" value="true"/> 
        </javaModelGenerator> 
        <!-- 生成映射文件的包名和位置--> 
        <sqlMapGenerator targetPackage="dao" targetProject=".\src"> 
            <property name="enableSubPackages" value="true"/> 
        </sqlMapGenerator> 
        <!-- 生成DAO的包名和位置--> 
        <javaClientGenerator type="XMLMAPPER" targetPackage="dao" targetProject=".\src"> 
            <property name="enableSubPackages" value="true"/> 
        </javaClientGenerator> 
        <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->
        <table tableName="branchinfo" domainObjectName="BranchInfo"></table>
        <table tableName="departinfo" domainObjectName="DepartInfo"></table>
        <!-- <table tableName="%"  enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> -->
    </context> 
</generatorConfiguration> 

************************************************备注**********************************************

 

【MyBatis】逆向工程

标签:ssd   false   word   let   select   enc   branch   注释   1.3   

原文地址:http://www.cnblogs.com/LightChan/p/7489230.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!