Camel 如何使用参数获取嵌套Map的值

7qhs6swi  于 2022-12-13  发布在  Apache
关注(0)|答案(1)|浏览(108)

我尝试使用SQL组件表达式的参数获取嵌套Map的值,但失败。
我有这个json(解组到java.util.Map):

{ "username" : "john",
  "company" : { "companycode" : "stackoverflow.inc",
                "address" : "Street 12" }
}

我的Route Builder上有一个带参数的SQL表达式:

...
.unmarshal().json(JsonLibrary.Jackson)
.to("sql:INSERT INTO user_tab VALUES (:#username, :#company.companycode)")
...

我可以得到username的值,但是我不能得到companycode的值。正确的方法是什么?谢谢。

mzillmmw

mzillmmw1#

依据:http://camel.apache.org/sql-component.html
从Camel 2.14开始,可以使用Simple表达式作为参数,如下所示:
sql:select * from table where id=:#${property.myId} order by name[?options]
这对我来说很好:
{guid=67, properties={last_seen=1472034553348, _type=business_service, name=Anna, created_at=1472033602648, status=USUNIĘTY}}
<to uri="dbSQL:insert into table_name ( guid,name,description,type,status,changedate,transid,transseq ) values ( :#${body[guid]}::integer, :#${body[properties][name]}, :#${body[properties][name]}, :#${body[properties][_type]}, :#${body[properties][staus]}, now(), 0, 0 )"/>

相关问题