查询多种状态时常会用到以下sql语句
select * form table A where A.state in(1,2)
之前都不知道如何在mybatis的mapper文件中实现,前几天问了下大佬,现在记录一下
<if test="paramBean != null and @Ognl@isNotEmpty(paramBean.states)">
AND STATE IN
<foreach collection="paramBean.states" item="paramBean.state" open="(" close=")" separator="," >
#{paramBean.state}
</foreach>
</if>
就是在vo中实现加一个states的数组,在mapper中将states遍历出来,同时前后加括号。
其实和在java代码中实现是没有本质上的区别