首页 > 解决方案 > 动态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>

即使 country=us 也总是生成 NOT IN

标签: javamybatisspring-mybatis

解决方案


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


推荐阅读