mybatis mapper.xml中根据参数动态拼接多个where条件
【代码】mybatis mapper.xml中根据参数动态拼接多个where条件。
·
1.dao传参
long commDeleteByConditions(@Param("tableName") String tableName, @Param("condition") Map conditions);
2. mapper.xml
<delete id="commDeleteByConditions">
delete from ${tableName}
<where>
<foreach collection="condition.keys" item="k1" separator="and">
<if test="@com.xxx.common.utils.SysUtils@isNotNullOrEmpty(condition[k1])">
<choose>
<when test="@com.xxx.common.utils.SysUtils@isCollection(condition[k1])">
${k1} in
<foreach collection="condition[k1]" item="v" separator="," open="(" close=")">
#{v}
</foreach>
</when>
<otherwise>
${k1} = #{condition[${k1}]}
</otherwise>
</choose>
</if>
<if test="@com.xxx.common.utils.SysUtils@isNullOrEmpty(condition[k1])">
(${k1} is null or ${k1} = '')
</if>
</foreach>
</where>
</delete>
更多推荐
已为社区贡献3条内容
所有评论(0)