与有关abilities of SuperCSV的帖子保持一致,SuperCSV是否可以处理更改从数据库读取的标头(列名仅)的值?

例如,以下代码段详细说明了当前状态和预期状态。

当前状态

输入:

final String[] header = new String[] { "firstName", "lastName", "birthDate"};

// write the header
beanWriter.writeHeader(header);

// write the beans
for( final CustomerBean customer : customers ) {
   beanWriter.write(customer, header, processors);
}

输出:具有列名称的文件:
firstName, lastName, birthDate
Bob      , Doe     , 02/12/2013

预期状态

输入:
final String[] header = new String[] { "firstName", "lastName", "birthDate"};

// write the header
beanWriter.writeHeader(header);

// write the beans
for( final CustomerBean customer : customers ) {
   beanWriter.write(customer, header, processors);
}

// modify the headers
 ??????

输出:列名已修改的文件:
First Name, Last Name, Birthday
Bob      , Doe     , 02/12/2013

非常感谢您的协助。

最佳答案

我不确定这是否能回答您的问题,但是您可以在标题中放入任何内容-它不必与传递给beanWriter.write()的映射数组相同

例如,以下内容将提供您想要的输出:

final String[] header = new String[] { "First Name", "Last Name", "Birthday"};
final String[] fieldMapping = new String[] { "firstName", "lastName", "birthDate"};

// write the header
beanWriter.writeHeader(header);

// write the beans
for( final CustomerBean customer : customers ) {
   beanWriter.write(customer, fieldMapping , processors);
}

08-05 19:23