mybatis if判断字符串

正确写法:

<if test="userCode != null and userCode !=''  
and userCode !='admin'.toString()">
或者
<if test='userCode != null and userCode !=""  
and userCode !="admin" '>

错误写法:

<if test="userCode != null and userCode !=""  
and userCode !='admin' ">

mybatis是使用的OGNL表达式来进行解析的,在OGNL的表达式中,"admin"会被解析成字符串,

因为java是强类型的,char 和 一个String 会导致不等。所以if标签中的sql不会被解析。

posted @ 2022-02-14 11:19  唏嘘-  阅读(270)  评论(0编辑  收藏  举报