如何在 Mulesoft 中检查 Arraylist 中的特定值?

How to check particular value in Arraylist in Mulesoft?

这是我的 ArrayList -

[  
   {  
      AccountNumber=123456,
      Amount=257710.06
   },
   {  
      AccountNumber=845679,
      Amount=3672351.06
   }
]

在这里,我想检查一下帐号123456是否在列表中。 我使用了 "Choice" 组件,因为我想创建另一个包含搜索帐号的列表。这是我的代码-

 <choice doc:name="Choice">
        <when expression="#[flowVars.investOneList.contains(123456)]">
            <logger message="Account number is present" level="INFO" doc:name="Logger"/>
        </when>
        <otherwise>
            <logger message="Account number is not present" level="INFO" doc:name="Logger"/>
        </otherwise>
    </choice>

在这里,我的记录器打印 "Account number is not present"。我的代码无法找到帐号,尽管它在列表中。 谁能帮帮我? 谢谢!

如果您想使用 List.contains(...),您需要像这样映射您拥有的变量:

%dw 1.0
%output application/java
---
flowVars.investOneList map $.AccountNumber

这会将 [123456, 845679] 作为 payload 输出(如果需要,您可以设置为其他内容)。然后您可以在您选择的路由器中执行此操作:

<choice doc:name="Choice">
        <when expression="#[payload.contains(123456)]">
            <logger message="Account number is present" level="INFO" doc:name="Logger"/>
        </when>
        <otherwise>
            <logger message="Account number is not present" level="INFO" doc:name="Logger"/>
        </otherwise>
    </choice>

但是您可以使用 dw() 函数在 MEL 中完成所有操作,如下所示:

...
<when expression="dw('(flowVars.investOneList map $.AccountNumber) contains 123456')">
...

这将避免您为了获得帐号列表而需要进行中间计算。