0

我想根据某些条件在 mule 应用程序中转换消息。

%dw 1.0
%output application/json
---
{
    **// create the below if the size of payload is greater than 0**
    resource_type : "speciality",
    speciality_name : payload[0].speciality_name,
    speciality_description : payload[0].speciality_description,
    uuid : payload[0].uuid

   **//else create the below message**
   message : "No records were fetched from backend"
}

有人可以帮我解决这个问题吗?

4

1 回答 1

4

您可以使用 when 否则条件。喜欢

%dw 1.0
%output application/json
---
{
    // create the below if the size of payload is greater than 0**
    resource_type : "speciality",
    speciality_name : payload[0].speciality_name,
    speciality_description : payload[0].speciality_description,
    uuid : payload[0].uuid
} when payload != null and (sizeOf payload) > 0 otherwise
{
   //else create the below message**
   message : "No records were fetched from backend"
}

希望这可以帮助。

于 2017-09-22T07:14:01.007 回答