2014-09-20 154 views
0

我在騾子是一個小問題處理數據.. 我選擇使用SQL查詢類似如下: -如何獲得使用MEL如果選擇SQL返回Null

<jdbc-ee:query key="RetriveQuery" value="Select NAME,ID from getData where ID=111 "/> 

現在,從這裏我會得到使用MEL像#[message.payload[0].NAME]

#[message.payload[0].ID] 

現在它可能是ID=111不存在的情況下的值.. 所以,在這種情況下,我怎麼能檢查查詢是否返回一個空負載或不使用MEL? ?..

到目前爲止,我試圖與選擇路由器類似如下: - :

-

<choice doc:name="Choice"> 
     <when expression="#[message.payload[0].ID == null]"> 

    //Then print in logger like Sorry!! Data not available 

否則每當我使用這個我得到以下異常使用MEL

打印在記錄儀中的數據

Exception stack is: 
1. Index: 0, Size: 0 (java.lang.IndexOutOfBoundsException) 
    java.util.ArrayList:604 (null) 
2. [Error: message.payload[0].ID: array index out of bounds.] 
[Near : {... message.payload[0].ID == null ....}] 
      ^
[Line: 1, Column: 1] (org.mule.mvel2.PropertyAccessException) 
    org.mule.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer:426 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/mvel2/PropertyAccessException.html) 
3. Execution of the expression "message.payload[0].ID == null" failed. (org.mule.api.expression.ExpressionRuntimeException) 
    org.mule.el.mvel.MVELExpressionLanguage:202 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/expression/ExpressionRuntimeException.html) 
4. Execution of the expression "message.payload[0].ID == null" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: ArrayList (org.mule.api.MessagingException) 
    org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:32 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html) 
-------------------------------------------------------------------------------- 
Root Exception stack trace: 
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 
    at java.util.ArrayList.rangeCheck(ArrayList.java:604) 
    at java.util.ArrayList.get(ArrayList.java:382) 
    at org.mule.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getCollectionProperty(ReflectiveAccessorOptimizer.java:776) 
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything) 

請幫助..我如何得到ID是否存在或不使用MEL?

回答

3

您可以使用message.payload.isEmpty()是決定表達式。

0

所以,感謝大衛,
工作代碼爲: -

<jdbc-ee:query key="RetriveQuery" value="Select NAME,ID from getData where ID=111 "/> 

<choice doc:name="Choice"> 
     <when expression="#[message.payload.isEmpty()]"> 

    //Then print in logger like Sorry!! Data not available 
相關問題