eclipse中myBatis引入

一、添加config.xml配置文件sql

二、定義與數據庫的數據實體映射類數據庫

三、建立操做表的是sql映射文件 即:mapper.xmlapp

四、在配置文件config.xml中註冊sql映射文件(步驟三建立的)ide

五、編寫調用類spa

配置懶加載:code

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

 

-----------------------------------------------------------------------xml

動態SQL:對象

    if標籤  <if  test="判斷條件">sql語句</if>blog

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

   多路條件判斷:<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>

相關文章
相關標籤/搜索