我在MyBatis映射器中有一个奇怪的错误,我可以检查参数是否为null但我无法检查相同参数的值;
以下是我的映射器的摘录:
<parameterMap id="OUTOCriteria" type="Map">
<parameter property="name" javaType="String" />
<parameter property="parentOU" javaType="Long" />
<parameter property="type" javaType="Integer" />
<parameter property="statusTypeCurrent" javaType="Integer" />
</parameterMap>
然后我会做这个检查:
<if test="parentOU != null">
<if test="parentOU.compareTo(new Long(1))">
AND OU_STRC_ID ${parentOU.operator.sql} #{parentOU.value}
</if>
</if>
第一次检查不会抛出任何错误,但嵌套检查会给我这个错误:
org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.apache.ibatis.builder.BuilderException: Error evaluating expression '!parentOU.compareTo(new Long(1))'. Cause: org.apache.ibatis.ognl.MethodFailedException: Method "compareTo" failed for object parentOUEQUAL1 [java.lang.NoSuchMethodException: compareTo(java.lang.Long)] ### The error may exist in com/clearstream/iam/query/sqlmaps/OU.xml ### The error may involve ou.iamouDefaultQuery ### The error occurred while executing a query ### Cause: org.apache.ibatis.builder.BuilderException: Error evaluating expression '!parentOU.compareTo(new Long(1))'. Cause: org.apache.ibatis.ognl.MethodFailedException: Method "compareTo" failed for object parentOUEQUAL1 [java.lang.NoSuchMethodException: compareTo(java.lang.Long)]
测试Long参数值的正确语法是什么?
答案 0 :(得分:3)
尝试这样的事情:
<if test="parentOU != null and parentOU.longValue() == 1">
AND OU_STRC_ID ${parentOU.operator.sql} #{parentOU.value}
</if>