Univocity - 将单行解析为多个 bean
Univocity - Parse single row into multiple beans
是否可以根据索引范围将单行解析成多个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")) {
}
您正在查找 @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;
}
希望对您有所帮助。
免责声明:我是这个图书馆的作者。它是开源且免费的(Apache 2.0 许可)
是否可以根据索引范围将单行解析成多个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")) {
}
您正在查找 @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;
}
希望对您有所帮助。
免责声明:我是这个图书馆的作者。它是开源且免费的(Apache 2.0 许可)