ibatis的iterate使用

          Iterate:這屬性遍歷整個(gè)集合,并為 List 集合中的元素重復(fù)元素體的內(nèi)容。
          Iterate 的屬性:?
          ??????prepend? - 可被覆蓋的 SQL 語句組成部分,添加在語句的前面(可選)?
          ??????property? - 類型為 java.util.List 的用于遍歷的元素(必選)?
          ??????open? -? 整個(gè)遍歷內(nèi)容體開始的字符串,用于定義括號(hào)(可選)?
          ??????close? -整個(gè)遍歷內(nèi)容體結(jié)束的字符串,用于定義括號(hào)(可選)?
          ??????conjunction -? 每次遍歷內(nèi)容之間的字符串,用于定義 AND 或 OR(可選)?
          ??????遍歷類型為 java.util.List的元素。

          例子:
          <iterate prepend=”AND” property=”userNameList”
          open=”(” close=”)” conjunction=”O(jiān)R”>
          username=#userNameList[]#
          </iterate>

          ibatis中如何配置in語句,需要迭代,不能直接用string的寫法
          <select id="sql_test" parameterclass="myPramBean" resultclass="myResult">
          select *from tablewhere name in
          <iterate property="ids" conjunction="," close=")" open="(" />
          #value[]#
          </iterate>
          and code=#code#
          </select>
          myPramBean
          {
          private String code;
          private List ids;
          ...
          }

          eg:
          <delete id="member.batchDelete" parameterClass="java.util.List">
          ? ?? ?DELETE FROM member where id IN
          ? ?? ?<iterate conjunction="," open="(" close=")" >
          ? ?? ??? ?#value[]#
          ? ?? ?</iterate>
          </delete>

          注意:使用<iterate>時(shí),在List元素名后面包括方括號(hào)[]非常重要,方括號(hào)[]將
          對(duì)象標(biāo)記為L(zhǎng)ist,以防解析器簡(jiǎn)單地將List輸出成String。

          posted on 2010-02-02 15:49 飛熊 閱讀(27193) 評(píng)論(3)  編輯  收藏 所屬分類: Ibatis

          評(píng)論

          # re: ibatis的iterate使用 2011-10-06 01:10 wiky

          ibatis中如何配置in語句,需要迭代,不能直接用string的寫法
          <select id="sql_test" parameterclass="myPramBean" resultclass="myResult">
          select *from tablewhere name in
          <iterate property="ids" conjunction="," close=")" open="(" />
          #value[]#
          </iterate>
          and code=#code#
          </select>

          #value[]# 要改成#ids[]# 才行  回復(fù)  更多評(píng)論   

          # re: ibatis的iterate使用[未登錄] 2013-08-22 13:36 呵呵

          第三種:in后面的數(shù)據(jù)確定,使用string傳入
          <select id="GetEmailList_Test2" parameterClass="TestIn" resultClass="EmailInfo_">
          select *
          from MailInfo with (nolock)
          where ID in
          ($StrValue$)
          </select>   回復(fù)  更多評(píng)論   

          # re: ibatis的iterate使用 2015-08-07 14:17 s'd'f

          adfasdfasgsdgasdf  回復(fù)  更多評(píng)論   

          <2015年8月>
          2627282930311
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          收藏夾

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 海晏县| 庆元县| 靖西县| 犍为县| 三河市| 海伦市| 临江市| 格尔木市| 正宁县| 霍州市| 辽宁省| 新田县| 兴业县| 城口县| 政和县| 社旗县| 高安市| 牡丹江市| 响水县| 全州县| 弋阳县| 平定县| 崇信县| 榆树市| 枞阳县| 安塞县| 霍邱县| 隆林| 保康县| 桦南县| 额敏县| 宿松县| 南岸区| 清苑县| 西华县| 汝南县| 武夷山市| 宣威市| 堆龙德庆县| 青田县| 靖安县|