mybatis中不经意遇到的坑!!!
每天记录一点
if 标签里判断条件拼接时 不能用大写字母
今天遇到的小坑,在测试接口中时,报告异常
// 报错信息
org.apache.ibatis.builder.BuilderException: Error evaluating expression 'item.warehouseId != null AND item.materialsId != null'. Cause: org.apache.ibatis.ognl.ExpressionSyntaxException: Malformed OGNL expression: item.warehouseId != null AND item.materialsId != null [org.apache.ibatis.ognl.ParseException: Encountered " <IDENT> "AND "" at line 1, column 26.
Was expecting one of:
<EOF>
"," ...
"=" ...
"?" ...
"||" ...
"or" ...
"&&" ...
"and" ...
"|" ...
"bor" ...
"^" ...
"xor" ...
"&" ...
"band" ...
"==" ...
"eq" ...
"!=" ...
"neq" ...
"<" ...
"lt" ...
">" ...
"gt" ...
"<=" ...
"lte" ...
">=" ...
"gte" ...
"in" ...
"not" ...
"<<" ...
"shl" ...
">>" ...
"shr" ...
">>>" ...
"ushr" ...
"+" ...
"-" ...
"*" ...
"/" ...
"%" ...
"instanceof" ...
"." ...
"(" ...
"[" ...
<DYNAMIC_SUBSCRIPT> ...
]
发现原来是代码中if
标签中连接条件时使用了大写的AND
//代码
<if test="item.warehouseId != null AND item.materialsId != null">
WHEN warehouse_materials.warehouse_id = #{ item.warehouseId}
AND warehouse_materials.materials_id = #{ item.materialsId}
THEN 1
</if>
改成小写就好了,应该用上报错信息中提示的关键字就好了
//代码
<if test="item.warehouseId != null and item.materialsId != null">
WHEN warehouse_materials.warehouse_id = #{ item.warehouseId}
AND warehouse_materials.materials_id = #{ item.materialsId}
THEN 1
</if>
特此记录一下小坑
还没有评论,来说两句吧...