zoukankan      html  css  js  c++  java
  • Mybatis-generator使用和扩展

    Mybatis-generator使用和扩展

    mybatis-generator使用
    pom.xml配置

    <plugin>
                    <groupId>org.mybatis.generator</groupId>
                    <artifactId>mybatis-generator-maven-plugin</artifactId>
                    <version>1.3.2</version>
                    <dependencies>
                        <!-- 数据库驱动  -->
                        <dependency>
                            <groupId>mysql</groupId>
                            <artifactId>mysql-connector-java</artifactId>
                            <version>5.1.6</version>
                        </dependency>
                        <dependency>
                            <groupId>org.mybatis.generator</groupId>
                            <artifactId>mybatis-generator-core</artifactId>
                            <version>1.3.2</version>
                        </dependency>
                        <dependency>
                            <groupId>org.mybatis</groupId>
                            <artifactId>mybatis</artifactId>
                            <version>3.2.8</version>
                        </dependency>
                            </exclusions>
                        </dependency>
                    </dependencies>
                    <configuration>
                        <verbose>true</verbose>
                        <overwrite>true</overwrite>
                    </configuration>
                </plugin>
    

    generatorConfig配置

    <?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">
    
    <!-- add by luobo 2016.4.18 使用时请自行修改 -->
    <generatorConfiguration>
        <!-- 引入配置文件 -->
        <properties resource="mybatis.generator.properties"/>
    
        <!-- 一个数据库一个context -->
        <context id="mysqlTables" targetRuntime="MyBatis3">
    
            <!-- 自定义扩展插件 -->
            <plugin type="com.yt.trade.dal.util.SqlMapperGeneratorExtend" >
                <property name="enableInsertSelective" value="false" />
            </plugin>
    
            <!-- 注释,type是使用自定义的类生成注释,这里我主要是想把数据库的字段说明带出来 -->
            <commentGenerator type="com.yt.trade.dal.util.YtCommentGenerator">
                <!-- 是否取消注释 -->
                <property name="suppressAllComments" value="true"/>
                <!-- 是否生成注释代时间戳-->
                <property name="suppressDate" value="true" />
            </commentGenerator>
    
            <!-- jdbc连接 -->
            <jdbcConnection driverClass="${jdbc_driver}"
                            connectionURL="${jdbc_url}"
                            userId="${jdbc_user}"
                            password="${jdbc_password}" />
    
            <!-- 类型转换 -->
            <javaTypeResolver>
                <!-- 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.) -->
                <property name="forceBigDecimals" value="false"/>
            </javaTypeResolver>
    
            <!-- 生成实体类地址 -->
            <javaModelGenerator targetPackage="com.yt.trade.dal.order.mapper.test" targetProject="src/main/java">
                <!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] -->
                <property name="enableSubPackages" value="false"/>
                <!-- 是否针对string类型的字段在set的时候进行trim调用 -->
                <property name="trimStrings" value="true"/>
            </javaModelGenerator>
    
            <!-- 生成mapxml文件 -->
            <sqlMapGenerator targetPackage="mapper.test" targetProject="src/main/resources">
                <property name="enableSubPackages" value="false"/>
            </sqlMapGenerator>
    
            <!-- 生成mapxml对应client,也就是接口dao -->
            <javaClientGenerator type="XMLMAPPER" targetPackage="com.yt.trade.dal.order.mapper" targetProject="src/main/java">
                <property name="enableSubPackages" value="false"/>
            </javaClientGenerator>
    
            <!-- 配置表信息 -->
            <!-- schema即为数据库名 tableName为对应的数据库表 domainObjectName是要生成的实体类 enable*ByExample 是否生成 example类   -->
            <table  tableName="t_order_assist"  domainObjectName="OrderAssist" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true"
                    enableInsert="true" enableCountByExample="false" enableSelectByExample="false" enableDeleteByPrimaryKey="false" enableUpdateByExample="false"  enableDeleteByExample="false" >
                <generatedKey column="id" sqlStatement="SELECT LAST_INSERT_ID()"/>
    
                <!-- 忽略列,不生成bean 字段 -->
                <ignoreColumn column="FRED" />
                <!-- 指定列的java数据类型 -->
                <columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" />
    
            </table>
    
            <!--
            <table  tableName="xxxx" domainObjectName="XXXX" enableCountByExample="false" enableSelectByExample="false" enableUpdateByExample="false" enableDeleteByExample="false">
                <generatedKey column="id" sqlStatement="SELECT LAST_INSERT_ID()"/>
            </table>
            -->
    
    
        </context>
    
    </generatorConfiguration>
    

    mybatis-generator扩展参考文档

  • 相关阅读:
    git stash
    vim 使用
    git 分支管理
    git 日常使用
    js createElement
    git checkout
    2.2链表 链表中倒数第k个结点
    1.8字符串及分析 翻转子串
    全排列
    1.7数组 清除行列
  • 原文地址:https://www.cnblogs.com/yissheng/p/5627796.html
Copyright © 2011-2022 走看看