zoukankan      html  css  js  c++  java
  • eclipse中myBatis引入

    1、添加config.xml配置文件

    2、定义与数据库的数据实体映射类

    3、创建操作表的是sql映射文件 即:mapper.xml

    4、在配置文件config.xml中注册sql映射文件(步骤三创建的)

    5、编写调用类

    配置懒加载:

    <settings>
            <setting name="lazyLoadingEnabled" value="true"/>
            <setting name="aggressiveLazyLoading" value="false"/>
    </settings>

    -----------------------------------------------------------------------

    动态SQL:

        if标签  <if  test="判断条件">sql语句</if>

     1 <if test="parkNum!=null and parkNum!=''"> 2 teneNo=#{parkNum}, 3 </if> 

       多路条件判断:<choose>

                                          <where test="判断条件">sql语句</where>

                  .............. -多个where语句

                    <otherwise test="判断添加">sql语句</otherwise>

                            </choose>

      where智能化标签:对于and的添加只能添加 (对于where不存在智能添加)

      set标签:智能添加 ,(应用于更新语句update)

    <update id="updatePark" parameterType="Park" statementType="PREPARED">
            update TENEPARK
            <set>
                <if test="parkNum!=null and parkNum!=''">
                    teneNo=#{parkNum},
                </if>
                <if test="parkName!=null and parkName!=''">
                    parkName=#{parkName},
                </if>
                <if test="updateTime!=null and updateTime!=''">
                    updateTime=to_timestamp(#{updateTime},'yyyy-mm-dd hh24:mi:ss')
                </if>
            </set>
            where id=#{id}
        </update>

      tirm标签:格式化标签,功能强大(被称为自定义标签)

               有以下的属性:prefix(前缀)和prefixOverides(前缀判断是否添加)  、suffix(后缀)和suffixOverides(后缀判断是否添加)

      foreach标签:

           <foreach item="迭代结果(单个对象)" index="循环到第几个' collection="集合" open="("开始标记  separator="分隔符(每个项之间)" close=")"结束标记 >

                    #{迭代结果(单个对象)}

           </foreach>

  • 相关阅读:
    c#多线程
    [2017.02.05] 阅读《Efficient C++》思维导图
    [2017.02.04] C++学习记录(1)
    [2017.01.04] 经典排序算法思想及其实现
    [2017.01.04] 2017 新年展望
    [151225] Python3 实现最大堆、堆排序,解决TopK问题
    [160111] Python学习记录
    [151116 记录] 使用Python3.5爬取豆瓣电影Top250
    151111 sqlite3数据库学习
    20141127 测试使用Word2013书写博客(代码高亮+公式支持)。
  • 原文地址:https://www.cnblogs.com/save-shengfei/p/5760365.html
Copyright © 2011-2022 走看看