原来正常的接口,今天调用的时候又异常了。
异常信息:nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 'null!=name AND name != '''. Cause: org.apache.ibatis.ognl.ExpressionSyntaxException: Malformed OGNL expression: null!=name AND name != '' [org.apache.ibatis.ognl.ParseException: Encountered \" <IDENT> \"AND \"\" at line 1, column 12.\r\nWas expecting one of:\r\n <EOF> \r\n \",\" ...\r\n \"=\" ...\r\n \"?\" ...\r\n \"||\" ...\r\n \"or\" ...\r\n \"&&\" ...\r\n \"and\" ...\r\n \"|\" ...\r\n \"bor\" ...\r\n \"^\" ...\r\n \"xor\" ...\r\n \"&\" ...\r\n \"band\" ...\r\n \"==\" ...\r\n \"eq\" ...\r\n \"!=\" ...\r\n \"neq\" ...\r\n \"<\" ...\r\n \"lt\" ...\r\n \">\" ...\r\n \"gt\" ...\r\n \"<=\" ...\r\n \"lte\" ...\r\n \">=\" ...\r\n \"gte\" ...\r\n \"in\" ...\r\n \"not\" ...\r\n \"<<\" ...\r\n \"shl\" ...\r\n \">>\" ...\r\n \"shr\" ...\r\n \">>>\" ...\r\n \"ushr\" ...\r\n \"+\" ...\r\n \"-\" ...\r\n \"*\" ...\r\n \"/\" ...\r\n \"%\" ...\r\n \"instanceof\" ...\r\n \".\" ...\r\n \"(\" ...\r\n \"[\" ...\r\n <DYNAMIC_SUBSCRIPT> ...\r\n \"(\" ...\r\n ]"
错误原因:
@Select({"<script>","SELECT * FROM lbs_device WHERE deleted = 0 AND app_id = #{appId} " +
"<if test=\"null!=name and name != ''\"> AND name=#{name}</if>" +
"<if test=\"null!=imei and imei != ''\"> AND imei=#{imei}</if>" +
"<if test=\"null!=enterpriseId and enterpriseId != -2\"> AND tenant_id=#{enterpriseId}</if>","</script>"})
List<DeviceEntity> queryPageList(@Param("name")String name , @Param("imei") String imei, @Param("appId") Long appId , @Param("enterpriseId") Long enterpriseId);
这个<if>判断的test条件不能使用AND,只能使用and