ibatis的iterate使用
Iterate 的屬性:?
??????prepend? - 可被覆蓋的 SQL 語(yǔ)句組成部分,添加在語(yǔ)句的前面(可選)?
??????property? - 類型為 java.util.List 的用于遍歷的元素(必選)?
??????open? -? 整個(gè)遍歷內(nèi)容體開(kā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語(yǔ)句,需要迭代,不能直接用string的寫(xiě)法
<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?飛熊?閱讀(20034)?評(píng)論(3)??編輯??收藏?所屬分類:?Ibatis
評(píng)論
#?re: ibatis的iterate使用?2011-10-06 01:10?wiky
ibatis中如何配置in語(yǔ)句,需要迭代,不能直接用string的寫(xiě)法
<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使用[未登錄](méi)?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>
轉(zhuǎn)載于:https://www.cnblogs.com/Struts-pring/p/5127500.html
總結(jié)
以上是生活随笔為你收集整理的ibatis的iterate使用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 正则表达式获取body内容
- 下一篇: zz bond配置网络: 两个网卡一个i