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>

posted @ 2016-08-11 11:36  DREAM_SF  阅读(3056)  评论(0编辑  收藏  举报