我在骡子有一个小问题.. 我正在使用如下所示的Select SQL查询: -
<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)
请帮助..如何使用MEL ???
获取ID是否存在答案 0 :(得分:3)
您可以使用message.payload.isEmpty()
作为决策表达。
答案 1 :(得分: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