定义band字段在 Mybatis中关于OGNL表达式会出现冲突Malformed OGNL expression
作者:互联网
表字段为band,band是捆绑的意思,与mybatis的OGNL表达式发生冲突
在网上察看了ognl表达式的setValue方法的源码后,总结了一下变量命名可能发生冲突的变量集合
:bor(字符|)的英文
xor 字符^的英文
and 字符&&
band 字符&
eq 字符==
neq 字符!=
lt 字符<
gt 字符>
lte 字符<=
gte 字符>=
shl 字符 <<
shr 字符>>
ushr 字符>>>
注意不能使用冲突的命名,其实是笔者,把brand写错了
mybatis编译的时候会报错,如下信息,
Caused by: org.apache.ibatis.ognl.ExpressionSyntaxException: Malformed OGNL expression: band != null
Error evaluating expression ' band!=null and #band !="" '. Cause: org.apache.ibatis.ognl.ExpressionSyntaxException: Malformed OGNL expression: band!=null and #band !="" [org.apache.ibatis.ognl.ParseException: Encountered "band" at line 1, column 2.
Was expecting one of:
":" ...
"not" ...
"+" ...
"-" ...
"~" ...
"!" ...
"(" ...
"true" ...
"false" ...
"null" ...
"#this" ...
"#root" ...
"#" ...
"[" ...
"{" ...
"@" ...
"new" ...
<IDENT> ...
<DYNAMIC_SUBSCRIPT> ...
"\'" ...
"`" ...
"\"" ...
<INT_LITERAL> ...
<FLT_LITERAL> ...
]
错误mybatis.xml
<if test=' band!=null and band !="" '>
AND test.band =#{band}
</if>
容易报错的 特殊命名
eq 对应字符 ==
neq 对应字符 !=
gt 对应字符 >
lte 对应字符 <
gte 对应字符 >=
lte 对应字符 <=
shl 对应字符 <<
shr 对应字符 >>
ushr 对应字符 >>>
band 对应字符 &
and 对应字符 &&
bor 对应字符 |
xor 对应字符 ^
标签:字符,ognl,...,band,OGNL,expression,对应 来源: https://blog.csdn.net/weixin_43064364/article/details/123204230