在mybaties中,要使用in进行查询,有三种传参方式:list,数组,map
1、list
select * from pub_user_role
<where>
area_code in
<foreach collection="list" index="index" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</where>
2、list
select * from pub_user_role
<where>
area_code in
<foreach collection="array" index="index" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</where>
3、map
select * from pub_user_role
<where>
area_code in
<foreach collection="ids" index="index" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</where>
此处的ids为封装在map里面的key值
前端传过来的参数为逗号分开的值,如:a,b,c,d等等。
再将次字符串转为list时,误使用arrays.aslist方法将其转为list,在使用pagehelp分页插件时,始终不显示第二页以后的数据,找了好久之后才发现是将参数转为list时出现了问题。