MyBatis报错:org.apache.ibatis.ognl.ExpressionSyntaxException: Malformed OGNL expression: shr!=null and shr!=”解决办法

完整报错信息:

严重: Servlet.service() for servlet [springDispatcherServlet] in context with path [/spfx] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 'shr!=null and shr!='' '. Cause: org.apache.ibatis.ognl.ExpressionSyntaxException: Malformed OGNL expression: shr!=null and shr!='' [org.apache.ibatis.ognl.ParseException: Encountered " "shr" "shr "" at line 1, column 1.
Was expecting one of:
 ":" ...
 "not" ...
 "+" ...
 "-" ...
 "~" ...
 "!" ...
 "(" ...
 "true" ...
 "false" ...
 "null" ...
 "#this" ...
 "#root" ...
 "#" ...
 "[" ...
 "{" ...
 "@" ...
 "new" ...
 <IDENT> ...
 <DYNAMIC_SUBSCRIPT> ...
 "\'" ...
 "`" ...
 "\"" ...
 <INT_LITERAL> ...
 <FLT_LITERAL> ...
 ]] with root cause
org.apache.ibatis.ognl.ParseException: Encountered " "shr" "shr "" at line 1, column 1.
Was expecting one of:
 ":" ...
 "not" ...
 "+" ...
 "-" ...
 "~" ...
 "!" ...
 "(" ...
 "true" ...
 "false" ...
 "null" ...
 "#this" ...
 "#root" ...
 "#" ...
 "[" ...
 "{" ...
 "@" ...
 "new" ...
 <IDENT> ...
 <DYNAMIC_SUBSCRIPT> ...
 "\'" ...
 "`" ...
 "\"" ...
 <INT_LITERAL> ...
 <FLT_LITERAL> ...

问题出现原因:

表字段‘审核人’简称为shr,与mybatis的OGNL表达式发生冲突。

问题出现位置:

插入方法没有用到OGNL表达式所以没问题,更新方法if语句用到了。

解决方法:

修改冲突的变量名即可。

总结了一下变量命名可能发生冲突的变量集合:

bor(字符|)的英文         
xor      字符^的英文       
and      字符&&     
band    字符&       
eq     字符==      
neq    字符!=     
lt      字符<    
gt      字符>    
lte       字符<=   
 gte    字符>=    
shl    字符 <<    
shr    字符>>     
ushr    字符>>>

涉及知识点:

OGNL表达式

参考:

https://zhidao.baidu.com/question/746327414942175612.html

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注