Mybatis写SQL语句注意

来源:互联网 发布:好玩的2d网络pc游戏 编辑:程序博客网 时间:2024/05/19 02:28


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>


   

原创粉丝点击