【问题标题】:Camel Bindy : configurable "pos" attribute in @DataFieldCamel Bindy:@DataField 中的可配置“pos”属性
【发布时间】:2013-10-04 15:41:43
【问题描述】:

我正在配置我的 POJO 以解组 CSV 行,所以我声明了我在 camel-bindy 官方页面上指示的属性,并且在解组时一切顺利。

@DataField(pos = 1) 
private String name; 
... 
getter and setter 

我需要做的是使pos 属性可配置,指向properties.file 中的相应属性以指示name 列在CSV 行中的位置。

是否有可能实现这样的行为?

【问题讨论】:

    标签: csv apache-camel bindy


    【解决方案1】:

    不,这是不可能的。并且没有计划在未来支持此功能。

    您可以查看其他一些 CSV 组件,例如 beanio,它允许在外部配置文件中定义绑定信息。

    【讨论】:

    • 感谢克劳斯的回复。 beanIO 可能是一种替代方案,或者我们可以只在专用处理器中处理 CSV 数据。
    【解决方案2】:

    我很想知道是否可以使用 Bindy,但文档中似乎没有任何说明。

    当您不确定属性位置的位置时,您可以做的是使用骆驼 CSV 数据解组。

    http://camel.apache.org/csv.html

    您创建一个路由来检查给定文件夹中的 csv 文件,将每个 csv 行解组到 List<String> 并将 List<List <String>> 发送到您将执行处理的 bean。 鉴于 csv 文件的第一行是列,在 bean 中,您将知道每个属性的位置,并且可以将 csv 数据字符串映射到 bean 的属性。

    路由该进程文件并解组行:

    <route>
        <from uri="file:///path/where/are/my/csvfiles?delete=true />
        <unmarshal><csv /></unmarshal>
        <to uri="bean:myCsvMapper?method=doHandleCsvData" />
    

    你的豆子:

    public void doHandleCsvData(List<List<String>> csvData){
       // with first line (column names) get the position of your attributes
    
       // for next lines do the mapping between the position and the attributes 
       // of your data bean
    }
    

    【讨论】:

    • 感谢弗雷德的回复。由于 bindy 不支持这种功能,因此按照您提到的手动处理 CSV 数据是有意义的。
    猜你喜欢
    • 1970-01-01
    • 2015-06-20
    • 2022-01-12
    • 1970-01-01
    • 1970-01-01
    • 2020-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多