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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM