2013-03-05 61 views
0

我在MyBatis映射器中有奇怪的錯誤,我可以檢查一個參數是否爲空,但我無法檢查相同參數的值;檢查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)] 

什麼是正確的語法來測試我的長參數的值?

回答

3

嘗試是這樣的:

<if test="parentOU != null and parentOU.longValue() == 1"> 
    AND OU_STRC_ID ${parentOU.operator.sql} #{parentOU.value} 
</if> 
+0

我試過'<如果測試= 「parentOU.value == 1」>'和它的工作。瘋狂的事情是它只在我明確使用語句中的'#{parentOU.value}'時才起作用。如果我不這樣做,那麼就會拋出一個錯誤。 – Lupuss 2013-03-05 14:47:35

+0

我想那是因爲Long對象比較複雜,試着用int或者long primitive – Vargan 2013-03-05 14:53:15