Cause: org.apache.ibatis.builder.BuilderException: Error evaluating expression 'sid ! =null and sid != '''. Cause: org.apache.ibatis.ognl.ExpressionSyntaxException: Malformed OGNL expression: sid ! =null and sid != '' [org.apache.ibatis.ognl.ParseException: Encountered " "!" "! "" at line 1, column 5.
Was expecting one of:
<EOF>
"," ...
"=" ...
"?" ...
"||" ...
"or" ...
"&&" ...
"and" ...
"|" ...
"bor" ...
"^" ...
"xor" ...
"&" ...
"band" ...
"==" ...
"eq" ...
"!=" ...
"neq" ...
"<" ...
"lt" ...
">" ...
"gt" ...
"<=" ...
"lte" ...
">=" ...
"gte" ...
"in" ...
"not" ...
"<<" ...
"shl" ...
">>" ...
"shr" ...
">>>" ...
"ushr" ...
"+" ...
"-" ...
"*" ...
"/" ...
"%" ...
"instanceof" ...
"." ...
"(" ...
"[" ...
<DYNAMIC_SUBSCRIPT> ...
"(" ...
]
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:196)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:67)
at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:145)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:86)
at com.sun.proxy.$Proxy9.updateMiddle(Unknown Source)
at com.nf.service.impl.NurPackageImpl.updateMiddle(NurPackageImpl.java:99)
... 28 more
当我们有的时候出现报错的时候,我们应看看系统的报错信息,大多数的报错,系统都是会给出具体的代码问题的,像我的报错如下:
Cause: org.apache.ibatis.builder.BuilderException: Error evaluating expression 'sid ! =null and sid != '''
这时,我们应该找到我们系统提示出错的代码中
下面是我的报错代码,我们发现 <if test="sid ! =null and sid != ''"> 第一个 ! 和 第二个 ! 中不一样,这时我们思考着是否是多了空格还是少了空格, 这时的我们应该二个都试一下
<update id="updateMiddle" parameterType="nurSerShop">
update nurs_ser_shop
<set>
<if test="sid ! =null and sid != ''">
sid = #{sid}
</if>
</set>
where id = #{id}
</update>
如下所示: 不错所料,我的代码中是多了一个空格,将代码中! 的空格去除
<if test="sid !=null and sid != ''">
sid = #{sid}
</if>
我们将空格去除之后,代码就会将完美的运行了