【问题标题】:Problem with "when and otherwise" condition“何时和其他”条件的问题
【发布时间】:2020-08-20 03:39:07
【问题描述】:

我会让代码做解释。

Dataweave 给出错误:

无法解析何时引用

无法解析其他情况的引用

输入消息:对象数组。虽然我在这里只给出了 1 个对象。

[{
    "Field1" : 12345,
    "field2" : 10
}]
%dw 2.0
output application/json
---
payload map {
"test" : $.Field1 when $.field2 >= 1 otherwise ""
}

【问题讨论】:

    标签: mule mule-studio dataweave mulesoft mule-esb


    【解决方案1】:

    Nadeem 在 DW 2.0 中没有 <expression> when <condition> otherwise <expression>。请改用if (condition) <then_expression> else <else_expression>

    所以你的代码如下:

    %dw 2.0
    output application/json
    var data = [{
        "Field1" : 12345,
        "field2" : 10
    }]
    ---
    data map {
        test : if  ($.field2 >= 1) $.Field1 else ""
    }
    

    【讨论】:

    • 那行得通。谢谢你。我真的应该研究一下 DW 1.0 和 2.0 之间的差异,尤其是在条件语句方面。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 2013-07-03
    • 1970-01-01
    • 2020-01-31
    • 2020-08-10
    相关资源
    最近更新 更多