mybatis:org.apache.ibatis.ognl.ParseException: Encountered " "OR "" at line 1, column 26错误解决

在mybatis项目中有一个sql做了对list集合做判空操作,sql如下:

<if test="personnelHasList == null OR personnelHasList.size == 0">
1
运行项目的时候发现时不时会出现以下报错情况:

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression ‘personnelHasList == null OR personnelHasList.size == 0’. Cause: org.apache.ibatis.ognl.ExpressionSyntaxException: Malformed OGNL expression: personnelHasList == null OR personnelHasList.size == 0 [org.apache.ibatis.ognl.ParseException: Encountered ” “OR “” at line 1, column 26. 
Was expecting one of: 

“,” … 
“=” … 
“?” … 
“||” … 
“or” … 
“&&” … 
“and” … 
“|” … 
“bor” … 
“^” … 
“xor” … 
“&” … 
“band” … 
“==” … 
“eq” … 
“!=” … 
“neq” … 
“<” … 
“lt” … 
“>” … 
“gt” … 
“<=” … 
“lte” … 
“>=” … 
“gte” … 
“in” … 
“not” … 
“<<” … 
“shl” … 
“>>” … 
“shr” … 
“>>>” … 
“ushr” … 
“+” … 
“-” … 
“*” … 
“/” … 
“%” … 
“instanceof” … 
“.” … 
“(” … 
“[” … 
… 
]] with root cause 
org.apache.ibatis.ognl.ParseException: Encountered ” “OR “” at line 1, column 26. 
Was expecting one of: 

“,” … 
“=” … 
“?” … 
“||” … 
“or” … 
“&&” … 
“and” … 
“|” … 
“bor” … 
“^” … 
“xor” … 
“&” … 
“band” … 
“==” … 
“eq” … 
“!=” … 
“neq” … 
“<” … 
“lt” … 
“>” … 
“gt” … 
“<=” … 
“lte” … 
“>=” … 
“gte” … 
“in” … 
“not” … 
“<<” … 
“shl” … 
“>>” … 
“shr” … 
“>>>” … 
“ushr” … 
“+” … 
“-” … 
“*” … 
“/” … 
“%” … 
“instanceof” … 
“.” … 
“(” … 
“[” … 

一开始在网上查询该报错信息,采纳了一个这样的说法:存在不合法的符号,  
导致xml解析不成功。于是从其他能运行通过的xml文件中复制了==号,发现  
还真的运行成功了,当时时间紧迫,手头还有其他任务,便没有仔细去验证多  
几次,如果多验证几次,就会发现实际问题还是存在(这一点我到现在也还没  
明白为何开始的时候可以运行成功),之后我试着将“OR”改成“or”和 改成  
“||”,发现就会没问题,初步判断是mybatis中不识别大写OR的原因。AND也不可以大写
--------------------- 
作者:caidie_huang 
来源:CSDN 
原文:https://blog.csdn.net/caidie_huang/article/details/81539466 
版权声明:本文为博主原创文章,转载请附上博文链接!

猜你喜欢

转载自blog.csdn.net/Amelia__Liu/article/details/94732897