ibatis的iterate使用

          Iterate:這屬性遍歷整個集合,并為 List 集合中的元素重復(fù)元素體的內(nèi)容。
          Iterate 的屬性:?
          ??????prepend? - 可被覆蓋的 SQL 語句組成部分,添加在語句的前面(可選)?
          ??????property? - 類型為 java.util.List 的用于遍歷的元素(必選)?
          ??????open? -? 整個遍歷內(nèi)容體開始的字符串,用于定義括號(可選)?
          ??????close? -整個遍歷內(nèi)容體結(jié)束的字符串,用于定義括號(可選)?
          ??????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>時,在List元素名后面包括方括號[]非常重要,方括號[]將
          對象標(biāo)記為List,以防解析器簡單地將List輸出成String。

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

          評論

          # 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ù)  更多評論   

          # 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ù)  更多評論   

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

          adfasdfasgsdgasdf  回復(fù)  更多評論   

          <2011年10月>
          2526272829301
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          導(dǎo)航

          統(tǒng)計

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          收藏夾

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 贺州市| 禄丰县| 桃园县| 南投市| 勐海县| 晋宁县| 靖安县| 彩票| 获嘉县| 建湖县| 茂名市| 新兴县| 湘乡市| 临湘市| 会理县| 留坝县| 卫辉市| 逊克县| 通化市| 米脂县| 牟定县| 扬中市| 日喀则市| 潮州市| 乐清市| 德格县| 奉节县| 秦皇岛市| 巨鹿县| 岳池县| 五台县| 巫溪县| 且末县| 宁远县| 宝兴县| 北碚区| 温宿县| 拉萨市| 策勒县| 左贡县| 西昌市|