优化后的SQL如下:

<when test="key != null and key == 'l3flag' ">
  <if test="!value.contains('')">
    <if test="!param.canSeachl3Flag()">
      and (
        <foreach collection="value" separator="or" item="item">
          issue.l3_flag like concat('%', #{item}, '%')
        </foreach>
      )
    </if>
    <if test="!param.canSeachl3Flag()">
      and (
        issue.l3_flag like '%是%否%' or issue.l3_flag like '%否%是%'
      )
    </if>
  </if>
  <if test="!value.contains('')">
    and issue.l3_flag is null
  </if>
</when>

优化说明:

  1. issue.l3_flag like <foreach>中的括号移到foreach标签的openclose属性中。
  2. 使用concat()函数代替字符串拼接操作。
  3. or连接的条件放在一个括号内,避免出现优先级问题。
  4. 将重复的条件判断!param.canSeachl3Flag()提取到外层if中,避免重复判断
优化下面SQLwhen test=key != null and key == l3flag if test=!valuecontainsif test=!paramcanSeachl3Flagand issuel3_flag like foreach collection=value separator= item=item open= close= #item foreachifif te

原文地址: https://www.cveoy.top/t/topic/iXJf 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录