问题描述
我有如下的csv数据。
我正在使用注释将csv数据转换为java对象。
我的Pojo类看起来像这样:
public class TeamEntity {
@CsvBindByName(column = "team_id")
private String teamId;
@CsvBindByName(column = "team_name")
private String teamName;
@CsvBindByName(column = "funds")
private int fund;
@CsvBindByName(column = "cars")
private String carId;
public TeamEntity() {
}
public TeamEntity(String teamId,String teamName,int fund,String carId) {
this.teamId = teamId;
this.teamName = teamName;
this.fund = fund;
this.carId = carId;
}
public String getTeamId() {
return teamId;
}
public void setTeamId(String teamId) {
this.teamId = teamId;
}
public String getTeamName() {
return teamName;
}
public void setTeamName(String teamName) {
this.teamName = teamName;
}
public int getFund() {
return fund;
}
public void setFund(int fund) {
this.fund = fund;
}
public String getCarId() {
return carId;
}
public void setCarIds(String carId) {
this.carId = carId;
}
}
我这样绑定它:
List<TeamEntity> teamEntities = new ArrayList<TeamEntity>();
try(Reader reader = Files.newBufferedReader(Paths.get(uri))) {
CsvToBean<TeamEntity> csvToBean = new CsvToBeanBuilder<TeamEntity>(reader)
.withType(TeamEntity.class)
.withIgnoreLeadingWhiteSpace(true)
.build();
teamEntities= csvToBean.parse();
} catch (IOException e) {
e.printstacktrace();
}
从数据中可以看到,如果将其转换为Java对象,则每个Car对象属性为 喜欢
String team_name;
String car_id;
double funds;
但是,我想将具有相同team_id的行合并并获得类似的内容,
String team_name;
List<String> car_id;
double funds;
实现它的最佳方法是什么?有什么办法可以使用注释吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)