代码之家  ›  专栏  ›  技术社区  ›  VedantK

动态mybatis xml查询

  •  0
  • VedantK  · 技术社区  · 6 年前

    需要有关以下动态查询的帮助:

    if country==null OR country != (spain || Peru)
    select * from emp where country NOT IN (spain,Peru)
    else
    select * from emp where country=#{country}
    

    我试过这样的方法,但没用:

    <when test="country ==null" or country !='spain' or country != 'Peru'">
                AND country NOT IN ('spain','peru')
                </when>
                <otherwise>
                AND country=#{country}
     </otherwise>
    

    即使国家=美国,也不会产生

    3 回复  |  直到 6 年前
        1
  •  1
  •   Code_Ninja Julius S.    6 年前

    试试这个 test="country == null or country != 'spain' or country != 'UK' "

        2
  •  0
  •   CheolHoJung    6 年前

    使用双引号来字符串。

    <when test='country == null or !country.equals("spain") or !country.equals("uk")'>
            AND country NOT IN ('spain','uk')
            </when>
            <otherwise>
            AND country=#{country}
     </otherwise>
    
        3
  •  0
  •   VedantK    6 年前
    <when test="country !='spain' and country != 'uk'">