有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java动态mybatis xml查询

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

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) 个答案

  1. # 1 楼答案

    使用双引号来表示字符串

    <when test='country == null or !country.equals("spain") or !country.equals("uk")'>
            AND country NOT IN ('spain','uk')
            </when>
            <otherwise>
            AND country=#{country}
     </otherwise>
    
  2. # 2 楼答案

    <when test="country !='spain' and country != 'uk'">
    

    错误的条件,预期的,而不是或

  3. # 3 楼答案

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