属性separator 为逗号
- 前段传过来的snapshotIds参数是list集合,类型为Integer或Long
select * from student_snapshot ss where 1=1
<if test="snapshotIds != null">
and ss.id in
<foreach collection="snapshotIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
最后渲染为sql语句为
and ss.id in (1,2,3)
- 前段传过来的snapshotView参数是list集合,类型为实体类对象
public class snapshotView {
private String snapshotIds = null;
private String gradIds = null;
private String classIds = null;
}
查询:
select * from student_snapshot ss where 1=1
<if test="snapshotView.snapshotIds != null">
and ss.id in ( ${snapshotView.snapshotIds} )
</if>
<if test="snapshotView.snapshotIds == null">
and ss.id in ( '' )
</if>
属性separator 为or
- 前段传过来的snapshotIds参数是list集合,类型为Integer或Long
select * from student_snapshot ss where 1=1
<if test="snapshotIds != null">
and
<foreach collection="snapshotIds" item="item" open="(" close=")" separator=",">
ss.id = #{item}
</foreach>
</if>
最后渲染为sql语句为
and ( ss.id = 1 or ss.id = 2 or ss.id = 3)
- 前段传过来的userId参数,查询实体类集合对象(什么方法查的无所谓)
List<SysDeptEntity> deptEntityList = currencyFeign.getDeptByUserId(userId);
SysDeptEntity:
public class SysDeptEntity {
private Long oid = null;
private String deptCode = null;
.....
}
查询:
select * from student_snapshot ss where 1=1
<if test="deptEntityList != null and deptEntityList.size() > 0">
and
<foreach collection="deptEntityList" item="item" open="(" close=")" separator="or">
ss.dept_code like concat(#{item.deptCode},'%')
</foreach>
</if>
<if test="deptEntityList == null or deptEntityList.size() == 0">
and ss.dept_coid = null
</if>
评论前必须登录!
注册