循环key:
<foreach collection="condition.keys" item="k" separator="and">
${k} = #{k} </foreach>
循环values
<foreach collection="condition.values" item="v" separator="and">
${v} = #{v} </foreach>
循环获取key和值:
<foreach collection="condition.keys" item="k" separator="and">
<if test="null != condition[k]"> ${k} = ${condition[k]} </if></foreach>
通常我们设置值的时候,会以#{}的方式,而不是${},如下
<foreach collection="condition.keys" item="k" separator="and">
<if test="null != condition[k]"> ${k} = #{condition[k]} </if></foreach>但是用这种方式,会发现,取不了值了,${condition[k]} 能取的出值,但#{condition[k]} 取出来的值却实null,正确的写法应该是:
<foreach collection="condition.keys" item="k" separator="and">
<if test="null != condition[k]"> ${k} = #{condition[${k}]} </if></foreach>