【发布时间】:2017-09-14 06:12:04
【问题描述】:
我在缓存中有数据,即对象存储。我需要从缓存中获取数据并对其应用过滤条件。
这里的要求是,我必须公开 api 以获取基于字段名称和字段值的数据,这将在请求中动态出现。
样品请求:
https://localhost:8082/api/customer/filter?fieldName=customerId&fieldValue=101810
我有返回代码来过滤 dataweave 中的数据,但它不起作用。你能帮忙吗?
%dw 1.0
%output application/json
---
payload.rows filter (("$.content." ++ flowVars.fieldName ++ ".content") as :string == flowVars.fieldValue as :string) map ((row , indexOfRow) -> {
customerId: row.content.customerId.content as :string when row.content.customerId.content != null otherwise null,
customerName: row.content.customerName.content as :string when row.content.customerName.content != null otherwise null,
customerAddress:row.content.customerAddress.content as :string when row.content.customerAddress.content != null otherwise null
})
我得到以下错误
Exception while executing:
payload.rows filter (("$.content." ++ flowVars.fieldName ++ ".content") as :string == flowVars.fieldValue as :string) map ((row , indexOfRow) -> {
^
Type mismatch for '++' operator
found :object, :string
required :string, :string.
你能帮忙吗
【问题讨论】:
-
请提供用于在objectstore或flowVars中设置fieldName和fieldValue的代码
-
我们将它们作为查询参数获取,这些参数将来自像这样的请求 fieldName=customerId&fieldValue=101810
-
从上面的映射中,我们将获取 fieldName 作为 customerId 或 CustomerName 或 CustomerAddress 来过滤数据,并且 filedVaule 是该字段的对应值。你能帮忙吗
-
请找到 input(json) as { "rows": [{ "label": "530", "content": { "customerId": { "content": 100002 }, "customerName" : { "content": "John" }, "customerAddress": { "content": "US" } } }, { "label": "530", "content": { "customerId": { "content": 100003 }, "customerName": { "content": "David" }, "customerAddress": { "content": "san diego" } } } ] }
标签: mule mule-studio mule-component mule-el mule-esb