概述
foreach属性主要有item,index,collection,open,separator,close。
1、item表示集合中每一个元素进行迭代时的别名,
2、index指定一个名字,用于表示在迭代过程中,每次迭代到的位置,
3、open表示该语句以什么开始,
4、separator表示在每次进行迭代之间以什么符号作为分隔符,
5、close表示以什么结束,
6、collection属性,该属性是必须指定的,但是在不同情况下,该属性的值是不一样的,主要有一下3种情况:
a、如果传入的是单参数且参数类型是一个List的时候,collection属性值为list .
b、如果传入的是单参数且参数类型是一个array数组的时候,collection的属性值为array .
c、如果传入的参数是多个的时候,我们就需要把它们封装成一个Map了,当然单参数也可以封装成map,实际上如果你在传入参数的时候,在MyBatis里面也是会把它封装成一个Map的,map的key就是参数名,所以这个时候collection属性值就是传入的List或array对象在自己封装的map里面的key.
<select id="findBy" resultMap="RfCustomerMemMap" parameterType="java.util.Map">
SELECT
<include refid="Column"/>
FROM rfl_customer_mem a LEFT JOIN rfl_loan b ON a.member_no = b.loan_member_no
WHERE a.member_no = #{memberNo} AND b.status IN
<foreach collection="status" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
<if test="name != null and name != ''">
AND name = #{name}
</if>
<if test="idNumber != null and idNumber != ''">
AND id_number = #{idNumber}
</if>
<if test="mobileNo != null and mobileNo != ''">
AND mobile_no = #{mobileNo}
</if>
<if test="loanNo != null and loanNo != ''">
AND loan_no = #{loanNo}
</if>
order by a.id DESC
<if test="offset > -1 and rows > -1">
limit #{offset},#{limit}
</if>
</select>
最后
以上就是眯眯眼黑猫为你收集整理的Mybatis查询sql中in语句使用的全部内容,希望文章能够帮你解决Mybatis查询sql中in语句使用所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复