您的位置:首页 > 其它

ibatis中 in的用法

2016-03-10 14:51 357 查看
本文摘自:http://stanlyy.iteye.com/blog/659686

ibatis中的sql语句处理in()的方法:

Xml代码


<select id="totalCustomSum" parameterClass="customReport" resultClass="customReport">

select sg.client_group_id as clientId, client_group_name as clientName,count(u.clientuser_id) as currentCount

From sys_client_group sg left join clientinfo_group g on sg.client_group_id = g.Client_group_id

left join user_info_msg u on u.clientuser_id= g.clientuser_id

<isNotEmpty property="startDate">

<![CDATA[ and u.createtime >= #startDate#]]>

</isNotEmpty>

<isNotEmpty property="endDate">

<![CDATA[ and u.createtime <= #endDate#]]>

</isNotEmpty>

<isNotEmpty property="userIdList">

and u.user_id in

<iterate property="userIdList" conjunction="," close=")" open="(" >

#userIdList[]#

</iterate>

</isNotEmpty>

group by sg.client_group_id

</select>

或者是:

Xml代码


<select id="totalCustomSum" parameterClass="customReport" resultClass="customReport">

select sg.client_group_id as clientId, client_group_name as clientName,count(u.clientuser_id) as currentCount

From sys_client_group sg left join clientinfo_group g on sg.client_group_id = g.Client_group_id

left join user_info_msg u on u.clientuser_id= g.clientuser_id

<isNotEmpty property="startDate">

<![CDATA[ and u.createtime >= #startDate#]]>

</isNotEmpty>

<isNotEmpty property="endDate">

<![CDATA[ and u.createtime <= #endDate#]]>

</isNotEmpty>

<isNotEmpty property="user_id">

and u.user_id in($user_id$)

</isNotEmpty>

group by sg.client_group_id

</select>

其中第二种方法注意 in()里面取值的符号是“$”而不是通常用的“#”

在另一个博客上写着:可以试试。

<select id="XXXX.list" parameterClass="java.util.ArrayList" resultClass="XXXXX">

select * from XXXX

<dynamic prepend=" where XXXX in">

<iterate open="(" close=")" conjunction="," >

#[]#

</iterate>

</dynamic>

</select>

传入一个List 用迭代器转换为 in (x,x,x,x,x,x,x……)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: