mybatis-generator的使用

实际项目中使用就是这么个使用,

 

 

一。在POM文件中引入plugin    
    <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>${mybatis.generator.version}</version>
                <configuration>
                    <configurationFile>src/main/generatorConfig.xml</configurationFile>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                </configuration>

                <dependencies>
                    <dependency>
                        <groupId>org.mybatis.generator</groupId>
                        <artifactId>mybatis-generator-core</artifactId>
                        <version>${mybatis.generator.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>tk.mybatis</groupId>
                        <artifactId>mapper</artifactId>
                        <version>3.3.6</version>
                    </dependency>
                    <dependency>
                        <groupId>org.postgresql</groupId>
                        <artifactId>postgresql</artifactId>
                        <version>9.4.1212</version>
                    </dependency>
                </dependencies>
            </plugin>




二。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>
    <context id="gen" targetRuntime="MyBatis3">
        <plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin">
        </plugin>
        <plugin type="org.mybatis.generator.plugins.SerializablePlugin">
        </plugin>
        <plugin type="org.mybatis.generator.plugins.ToStringPlugin"></plugin>
        <commentGenerator>
            <property name="suppressDate" value="true" />
            <property name="suppressAllComments" value="true" />
        </commentGenerator>
        <!--数据库url、用户名和密码 -->
        <jdbcConnection driverClass="org.postgresql.Driver"
            connectionURL="jdbc:postgresql://xxx:7518/ipfcs?useUnicode=true&amp;characterEncoding=utf-8&amp;useSSL=false" userId="user" password="pass">
        </jdbcConnection>
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false" />
        </javaTypeResolver>
        <!--实体类 -->
        <javaModelGenerator targetPackage="com.xxx.xxx.xx.xxx" targetProject="src\main\java">
            <property name="enableSubPackages" value="true" />
            <property name="trimStrings" value="true" />
        </javaModelGenerator>
        <!--Mapping映射文件 -->
        <sqlMapGenerator  targetPackage="mapper" targetProject="src\main\resources">
            <property name="enableSubPackages" value="true" />
        </sqlMapGenerator>
        <!--DAO接口 -->
        <javaClientGenerator
            targetPackage="com.xxxxx.xxxxx.xxxxx.xxxx.xxxxxx" targetProject="src\main\java"  type="XMLMAPPER">
            <property name="enableSubPackages" value="true" />
        </javaClientGenerator>
        <!--tableName需使用小写,domainObjectName为生成的pojo对象类名-->

            
            <table  tableName="table_name" domainObjectName="pojo_nale"
            enableCountByExample="false" enableUpdateByExample="false"
            enableDeleteByExample="false" enableSelectByExample="false"
            selectByExampleQueryId="false" />
            
    </context>
</generatorConfiguration>

posted @ 2020-10-21 09:35  小__七  阅读(580)  评论(0)    收藏  举报