Java 在Apache Camel中输出CSV列标题
是否可以在此页面上的“将地图编组为CSV”示例中输出标题行 期望输出:Java 在Apache Camel中输出CSV列标题,java,csv,apache-camel,marshalling,Java,Csv,Apache Camel,Marshalling,是否可以在此页面上的“将地图编组为CSV”示例中输出标题行 期望输出: foo,bar abc,123 您需要使用支持配置标头的Camel 2.15及以后版本。请参阅文档: camel csv的单元测试有一些例子 我定义了一个List的聚合器,该聚合器将Map.get(0).keySet()添加为聚合列表的元素0(例如oldExchange==null)。聚合完成后,我对结果调用了marshal().csv()。使用SpringXML Using spring xml <m
foo,bar
abc,123
您需要使用支持配置标头的Camel 2.15及以后版本。请参阅文档: camel csv的单元测试有一些例子
我定义了一个
List
的聚合器,该聚合器将Map.get(0).keySet()添加为聚合列表的元素0(例如oldExchange==null
)。聚合完成后,我对结果调用了marshal().csv()
。使用SpringXML
Using spring xml
<multicast stopOnException="true">
<pipeline>
<log message="saving table ${headers.tablename} header to ${headers.CamelFileName}..."/>
<setBody>
<groovy>request.headers.get('CamelJdbcColumnNames').join(";") + "\n"</groovy>
</setBody>
<to uri="file:output"/>
</pipeline>
<pipeline>
<log message="saving table ${headers.tablename} rows to ${headers.CamelFileName}..."/>
<marshal>
<csv delimiter=";" headerDisabled="false" useMaps="true"/>
</marshal>
<to uri="file:output?fileExist=Append"/>
</pipeline>
</multicast>
使用springxml
request.headers.get('CamelJdbcColumnNames').join(“;”)+“\n”
再见matteo在运行时之前,是否可以在CsvMarshalPipeDelimiterTest.testCsvMarshal()中输出单个标题(orderId、item、amount),而不知道LinkedHashMap.keySet()?问这个问题的另一种方式是,是否可以在CsvMarshalTest.shouldHandleColumns()中输出单个头(a,C),而不知道Map.keySet()在createRouteBuilder()中是[a,C](直到运行时)?不确定,但听起来是个好主意,使用键名作为头。欢迎您登录JIRA ticketdoes,这意味着如果未配置标题,它们将不会出现在csv中?假设我有来自jdbc的结果集,当我只显示时,列的标题不会显示在csv中。
foo,bar
abc,123
Using spring xml
<multicast stopOnException="true">
<pipeline>
<log message="saving table ${headers.tablename} header to ${headers.CamelFileName}..."/>
<setBody>
<groovy>request.headers.get('CamelJdbcColumnNames').join(";") + "\n"</groovy>
</setBody>
<to uri="file:output"/>
</pipeline>
<pipeline>
<log message="saving table ${headers.tablename} rows to ${headers.CamelFileName}..."/>
<marshal>
<csv delimiter=";" headerDisabled="false" useMaps="true"/>
</marshal>
<to uri="file:output?fileExist=Append"/>
</pipeline>
</multicast>