mybatis-generator插件的使用

做个记录,方便用到时查询

1、在pom文件中引入插件


    <build>
        <plugins>
            <plugin>
                <groupId>org.mybatis.generatorgroupId>
                <artifactId>mybatis-generator-maven-pluginartifactId>
                <version>1.3.3version>
                <configuration>
                    <configurationFile>${project.basedir}/src/main/resources/mybatis/generatorConfig.xmlconfigurationFile>
                configuration>
            plugin>
        plugins>
    build>

2、编写generatorConfig.xml配置文件
配置文件可以参考下面的代码:




<generatorConfiguration>
    
    <classPathEntry location="E:\workspace\src\main\resources\mybatis\mysql-connector-java-5.1.8.jar"/>
    
    <context id="MysqlTables" targetRuntime="MyBatis3">
        


        
        
        <commentGenerator>
            
            <property name="suppressAllComments" value="true"/>
        commentGenerator>

        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/test"
                        userId="root"
                        password="123456">
        jdbcConnection>

        
        <javaTypeResolver>
            
            
            <property name="forceBigDecimals" value="false"/>
        javaTypeResolver>
        
        <javaModelGenerator targetPackage="com.test.dal.dao" targetProject="E:\workspace\code\src\main\java">
            
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        javaModelGenerator>
        
        <sqlMapGenerator targetPackage="xml" targetProject="E:\workspace\src\main\resources">
            
            <property name="enableSubPackages" value="true"/>
        sqlMapGenerator>

        
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.test.dal.dao" targetProject="E:\workspace\code\src\main\java">
            <property name="enableSubPackages" value="true"/>
        javaClientGenerator>

        
        <table schema="aaa" tableName="test2" domainObjectName="Test2">

            
            <property name="useActualColumnNames" value="false"/>
            
            <columnOverride column="DATE_FIELD" property="startDate"/>
            <ignoreColumn column="FRED"/>
            <columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR"/>
        table>
    context>
generatorConfiguration>

你可能感兴趣的:(mybatis)