0

我在 MyBatis 映射器中有一个奇怪的错误,我可以在其中检查参数是否为空,但无法检查同一参数的值;

这是我的映射器的摘录:

<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 参数值的正确语法是什么?

4

1 回答 1

3

尝试这样的事情:

<if test="parentOU != null and parentOU.longValue() == 1">
    AND OU_STRC_ID ${parentOU.operator.sql} #{parentOU.value}
</if>
于 2013-03-05T14:25:50.200 回答