当前位置: 代码迷 >> SQL >> Mybatis写SQL话语注意
  详细解决方案

Mybatis写SQL话语注意

热度:91   发布时间:2016-05-05 12:05:28.0
Mybatis写SQL语句注意


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>


   

  相关解决方案