mybatis笔记

  1. 开启驼峰命名

    <configuration>
        <!-- 全局配置 -->
        <settings>
            <!--允许 JDBC 支持自动生成主键-->
            <setting name="useGeneratedKeys" value="false"/>
        <!--是否开启自动驼峰命名规则(camel case)映射,即从经典数据库列名 A_COLUMN 到经典Java 属性名 aColumn 的类似映射。 -->
            <setting name="mapUnderscoreToCamelCase" value="true"/>
        </settings>
    </configuration>
    
  2. 批量insert

    <insert id="insertByBatch" parameterType="java.util.List">
        insert into attachment_table (name, logID,url)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.name,jdbcType=VARCHAR}, #{item.logid,jdbcType=INTEGER},#{item.url,jdbcType=LONGVARCHAR})
        </foreach>
    </insert>
    
  3. Spring, MyBatis 多数据源的配置和管理

  4. 生成entity的toString方法

    <plugin type="org.mybatis.generator.plugins.SerializablePlugin" />
    <plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin" />
    <plugin type="org.mybatis.generator.plugins.ToStringPlugin" />
    <commentGenerator>
    <!-- 抑制生成代码的注释 -->
    <property name="suppressAllComments" value="true" />
    </commentGenerator>
    

    参考:
    http://www.mybatis.org/generator/reference/plugins.html
    http://www.mybatis.org/generator/configreference/plugin.html

  5. 生成器手动指定字段映射

    <table tableName="表名" domainObjectName="实体名">
        <columnOverride column="字段1" property="属性名"/>
        <columnOverride column="字段2" property="属性名"/>
        ...
    </table>
    
  6. MyBatis Generator实现MySQL分页插件
    参考

  7. @

posted @ 2017-09-03 17:19  liqipeng  阅读(160)  评论(0编辑  收藏  举报