1.mybatis where 动态查询时,首个查询语句的首个单词中不要出现sql的关键字
比如:
<where>
<if test="orgIds !=null">
org.id IN
<foreach collection="orgIds" item="item" index="index" open="("
separator="," close=")">
#{item}
</foreach>
</if>
AND coupon.isdel = 0
</where>其中org 的前两个字母是 or ,和sql的关键字 OR 是一样的所以会截取 按 g.id IN 来查询
解决方案:
和 coupon.isdel = 0 调换一下位置便可(屏蔽关键字):
<where>
coupon.isdel = 0
<if test="orgIds !=null">
AND org.id IN
<foreach collection="orgIds" item="item" index="index" open="("
separator="," close=")">
#{item}
</foreach>
</if>
</where>
本文探讨了在使用MyBatis进行动态SQL查询时遇到的一个常见问题:首个查询语句的单词不能包含SQL关键字,否则会导致查询结果不正确。通过调整查询语句的位置可以有效解决该问题。
1312

被折叠的 条评论
为什么被折叠?



