<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    風人園

    弱水三千,只取一瓢,便能解渴;佛法無邊,奉行一法,便能得益。
    隨筆 - 99, 文章 - 181, 評論 - 56, 引用 - 0
    數據加載中……

    iBATIS如何復用SQL片段(zt)

    原文鏈接

    http://opensource.atlassian.com/confluence/oss/display/IBATIS/How+do+I+reuse+SQL-fragments


    When writing SqlMaps, you often encounter duplicate fragments of SQL, for example a FROM-clause or constraint-statement; iBATIS offers a simple yet powerful tag to reuse them. For the sake of simplicity, let's assume we want to get some items and we want to do a count on them.

    Normally, you would write something like this:

    當我們寫SqlMaps的時候,經常會碰到重復的SQL片段,例如From語句或者約束條件;iBATIS提供了一個強大的標簽來復用這些重復片段,簡單舉例,我們想檢索一些字段,并且想統計它們。

    通常情況下,你會這樣寫:

    xml 代碼
    1. < select ? id = "selectItemCount" ? resultClass = "int" > ?? ??
    2. ??SELECT?COUNT(*)?AS?total??? ??
    3. ??FROM?items??? ??
    4. ??WHERE? parentid ?=? 6 ?? ??
    5. </select > ?? ??
    6. < select ? id = "selectItems" ? resultClass = "Item" > ?? ??
    7. ??SELECT?id,?name??? ??
    8. ??FROM?items??? ??
    9. ??WHERE? parentid ?=? 6 ?? ??
    10. </select > ?? ??
    11. ??

    ?To eliminate this duplication, we use the tags 【sql】 and 【include】. The 【sql】-tag contains the fragment to reuse, the 【include】-tag to include such a fragment:

    為了消除重復片段,我們使用【sql】和【include】標簽。【sql】標簽用來包含重復片段,【include】標簽用來引入片段:

    ?xml 代碼

    1. < sql ? id = "selectItem_fragment" > ?? ??
    2. ??FROM?items??? ??
    3. ??WHERE? parentid ?=? 6 ?? ??
    4. </sql > ?? ??
    5. < select ? id = "selectItemCount" ? resultClass = "int" > ?? ??
    6. ??SELECT?COUNT(*)?AS?total??? ??
    7. ?? < include ? refid = "selectItem_fragment" /> ?? ??
    8. </select > ?? ??
    9. < select ? id = "selectItems" ? resultClass = "Item" > ?? ??
    10. ??SELECT?id,?name??? ??
    11. ?? < include ? refid = "selectItem_fragment" /> ?? ??
    12. </select > ?? ??
    13. ??

    ?The 【include】-tag is namespace-aware so you can refer to fragments even when they are located in another map (however, due to the way iBATIS loads the SqlMaps, the included fragment should be loaded before the including statement).?

    【inclued】標簽是一個命名空間可知的,所以你可以引入其他map的片段.(但是,因為iBATIS引入SqlMap的順序,被引入的片段,要優先于欲引入的sql部分被導入)

    The fragments are included and processed on query-execution so parameters can be used too:

    重復片段在查詢執行時被引入和執行,所以參數依然可以使用:

    ?xml 代碼

    1. < sql ? id = "selectItem_fragment" > ?? ??
    2. ??FROM?items??? ??
    3. ??WHERE? parentid ?=?#value#??? ??
    4. </sql > ?? ??
    5. < select ? id = "selectItemCount" ? parameterClass = "int" ? resultClass = "int" > ?? ??
    6. ??SELECT?COUNT(*)?AS?total??? ??
    7. ?? < include ? refid = "selectItem_fragment" /> ?? ??
    8. </select > ?? ??
    9. < select ? id = "selectItems" ? parameterClass = "int" ? resultClass = "Item" > ?? ??
    10. ??SELECT?id,?name??? ??
    11. ?? < include ? refid = "selectItem_fragment" /> ?? ??
    12. </select > ?? ??

    posted on 2006-12-16 14:38 風人園 閱讀(613) 評論(0)  編輯  收藏 所屬分類: DAO

    主站蜘蛛池模板: 本免费AV无码专区一区| 极品色天使在线婷婷天堂亚洲| a级毛片免费网站| 亚洲色婷婷综合开心网| 免费人成视频在线观看免费| 免费人成网站在线播放| 青青免费在线视频| 亚洲精品国产成人影院| h片在线播放免费高清| 亚洲日韩小电影在线观看| 91精品成人免费国产| 亚洲va久久久噜噜噜久久男同 | 亚洲喷奶水中文字幕电影| 91久久青青草原线免费| 亚洲毛片一级带毛片基地| 毛片免费视频在线观看| 亚洲欧美成人av在线观看| 亚洲不卡无码av中文字幕| 国产区在线免费观看| 亚洲一区二区三区电影| AV免费网址在线观看| 有码人妻在线免费看片| 国产成人精品日本亚洲网站 | 天天摸天天碰成人免费视频| 苍井空亚洲精品AA片在线播放| 亚洲成?Ⅴ人在线观看无码| baoyu116.永久免费视频| 亚洲韩国在线一卡二卡| 免费毛片在线播放| 一区二区三区免费精品视频 | 亚洲AV成人潮喷综合网| 免费一级不卡毛片| 亚洲国产成人91精品| 亚洲 综合 国产 欧洲 丝袜| 精品国产麻豆免费人成网站| 亚洲精品一二三区| 青青草原亚洲视频| 99视频全部免费精品全部四虎| 看Aⅴ免费毛片手机播放| 亚洲va在线va天堂va四虎| 白白国产永久免费视频|