Mybatis自動生成的配置實例

1、目錄java

按照圖片準備下面的東西吧,基礎jar,數據連接庫的jar。mysql

2、generatorConfig.xmllinux

<?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"/>    
    <!-- <classPathEntry location="sqljdbc4.jar"/> -->    
    <context id="mybatis">
        <commentGenerator>
            <!-- 是否去除自動生成的註釋 true:是 : false:否 -->
            <!-- <property name="suppressAllComments" value="true" /> -->
            <property name="suppressDate" value="true"/>
        </commentGenerator>
        
       <!-- 數據庫鏈接的信息:驅動類、鏈接地址、用戶名、密碼 -->
       <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://127.0.0.1:3306/testDb?characterEncoding=utf8" userId="root"
                        password="123456">
        </jdbcConnection>
        <!-- sqlserver的示例 -->
        <!-- 
        <jdbcConnection driverClass="com.microsoft.sqlserver.jdbc.SQLServerDriver"
                        connectionURL="jdbc:sqlserver://127.0.0.1;DatabaseName=testDb" userId="root"
                        password="123456">
        </jdbcConnection>
        -->
        <javaModelGenerator targetPackage="com.your.real.package.name.model.base"
                            targetProject="src">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>

        <sqlMapGenerator targetPackage="com.your.real.package.name.dao.mapper"
                         targetProject="src">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>

        <javaClientGenerator type="XMLMAPPER"
                             targetPackage="com.your.real.package.name.dao"
                             targetProject="src">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>

        <!-- tableName:用於自動生成代碼的數據庫表;domainObjectName:對應於數據庫表的javaBean類名 -->
        <!-- linux表名區分大小寫 -->
        <table tableName="test_tb" domainObjectName="TestTb"></table>
    </context>
</generatorConfiguration>

3、run.batsql

java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite
mvn mybatis-generator:generate
相關文章
相關標籤/搜索