动态 mybatis xml 查询
dynamic mybatis xml query
需要以下动态查询的帮助:
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>
始终生成 NOT IN,即使 country=us
试试这个 test="country == null or country != 'spain' or country != 'UK' "
对字符串使用双引号。
<when test='country == null or !country.equals("spain") or !country.equals("uk")'>
AND country NOT IN ('spain','uk')
</when>
<otherwise>
AND country=#{country}
</otherwise>
<when test="country !='spain' and country != 'uk'">
错误的条件,预期的而不是 or
需要以下动态查询的帮助:
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>
始终生成 NOT IN,即使 country=us
试试这个 test="country == null or country != 'spain' or country != 'UK' "
对字符串使用双引号。
<when test='country == null or !country.equals("spain") or !country.equals("uk")'>
AND country NOT IN ('spain','uk')
</when>
<otherwise>
AND country=#{country}
</otherwise>
<when test="country !='spain' and country != 'uk'">
错误的条件,预期的而不是 or