1

是否可以根据索引范围将单行解析为多个 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")) {  

}
4

1 回答 1

1

您正在寻找@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 许可证)

于 2019-05-31T12:10:57.483 回答