<select id="querySqlByParams" resultType="java.util.Map" statementType="STATEMENT"> select * from (${sql} <where> <foreach collection="params.keys" item="k" index="index" separator=" and "> <if test="null!=params[k]"> ${k}=${params[k]} </if> </foreach> </where> ) </select> <select id="querySqlByParams" resultType="java.util.Map" statementType="STATEMENT"> select * from (${sql} <where> <if test="null!=params.values and params.values.size()>0"> id in <foreach collection="params.values" item="v" open="values (" close=")" separator=","> #{v} </foreach> </if> </where> ) </select>
当然<foreach collection="params.values"/>也是可以使用,记录以后好查询