首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Univocity将单个行分解为多个bean

Univocity将单个行分解为多个bean
EN

Stack Overflow用户
提问于 2019-05-30 18:35:10
回答 1查看 153关注 0票数 1

是否可以根据索引范围将一行解析为多个bean?

示例

行:"field1“、"field2”、"field3“、.、"field9”

代码语言:javascript
复制
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")) {  

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-31 12:10:57

您正在寻找@Nested注释。只需使用:

代码语言:javascript
复制
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许可证)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56383831

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档