我正在配置我的POJO以解组CSV行,所以我在camel-bindy官方页面上显示了我的属性,并且在解组时一切顺利。
@DataField(pos = 1)
private String name;
...
getter and setter
我需要做的是使pos
属性可配置,将相应的属性指向properties.file以指示CSV行中name
列的位置。
是否可以实施此类行为?
答案 0 :(得分:0)
我很想知道是否可以与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
}
答案 1 :(得分:0)
不,这是不可能的。并且没有计划在未来支持这一点。
您可以查看一些其他CSV组件,例如beanio,它允许在外部配置文件中定义绑定信息。