ibatis中的sql语句处理in()的方法:
<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>
或者是:
<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()里面取值的符号是“$”而不是通常用的“#”