是否可以根据索引范围将一行解析为多个bean?
示例
行:"field1“、"field2”、"field3“、.、"field9”
class ColumnsOneAndTwo {
protected String field1;
protected String field2;
}
class ColumnThreeAndNine {
protected String field3;
protected String field9;
}
class Row {
@Parsed(indexes = 0, 1)
protected ColumnOneAndTwo fields;
@Parsed(indexes = 2, 8)
protected ColumnThreeAndNine moreFields;
}
BeanListProcessor<Row> rowProcessor = new BeanListProcessor<Row>(Row.class);
CsvRoutines routines = new CsvRoutines(parserSettings);
for (Row data : routines.iterate(Row.class, <file>, "UTF-8")) {
}发布于 2019-05-31 12:10:57
您正在寻找@Nested注释。只需使用:
class ColumnsOneAndTwo {
@Parsed(index=1)
protected String field1;
@Parsed(index=2)
protected String field2;
}
class ColumnThreeAndNine {
@Parsed(index=3)
protected String field3;
@Parsed(index=9)
protected String field9;
}
class Row {
@Nested
protected ColumnOneAndTwo fields;
@Nested
protected ColumnThreeAndNine moreFields;
} 希望能帮上忙。
免责声明:我是这个图书馆的作者。它是开放源码和免费的(Apache2.0许可证)
https://stackoverflow.com/questions/56383831
复制相似问题