zoukankan      html  css  js  c++  java
  • 利用MyBatis生成器自动生成实体类、DAO接口和Mapping映射文件

    1、 mybatis-generator-core-1.3.5.jar

      下载地址:https://github.com/mybatis/generator/releases

    2、 msyql-connector-java-5.1.30.jar

      网上下载。

    3、 配置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="mysql-connector-java-5.1.30.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://10.211.55.8/bigdata" userId="root" password="bigdata">    
            </jdbcConnection>    
            <javaTypeResolver>    
                <property name="forceBigDecimals" value="false"/>    
            </javaTypeResolver>    
            <!-- 生成模型的包名和位置-->    
            <javaModelGenerator targetPackage="com.bigdata.mybatis.domain" targetProject="src">    
                <property name="enableSubPackages" value="true"/>    
                <property name="trimStrings" value="true"/>    
            </javaModelGenerator>    
            <!-- 生成映射文件的包名和位置-->    
            <sqlMapGenerator targetPackage="com.bigdata.mybatis.mapping" targetProject="src">    
                <property name="enableSubPackages" value="true"/>    
            </sqlMapGenerator>    
            <!-- 生成DAO的包名和位置-->    
            <javaClientGenerator type="XMLMAPPER" targetPackage="com.bigdata.mybatis.IDao" targetProject="src">    
                <property name="enableSubPackages" value="true"/>    
            </javaClientGenerator>    
            <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->    
            <table tableName="user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>  
        </context>    
    </generatorConfiguration>    

    三个文件存放如下:

    4、 根据命令产生文件,在目录下新建一个src文件夹

    java -jar mybatis-generator-core-1.3.5.jar -configfile generatorConfig.xml -overwrite

      这样在生成之后,就可以在src目录下找到相应的文件夹,每个表都会对应三个文件(实体类、接口、配置文件)。

  • 相关阅读:
    解决MVC的Controller和Web API的Controller类名不能相同的问题
    SSO的踢人模式/禁入模式
    os处理文件
    pyton mock
    python xml转换成json
    python调用jpype
    Python程序的执行过程原理(解释型语言和编译型语言)
    python 字典、列表、字符串 之间的转换
    python接口自动化1
    不用框架,原生使用python做注册接口/登陆接口/充值接口的测试,做的数据/代码分离
  • 原文地址:https://www.cnblogs.com/aaron911/p/10029063.html
Copyright © 2011-2022 走看看