符合这个帖子关于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);
}
OUTPUT:包含列名的文件:
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
非常感谢任何帮助。
最佳答案
我不确定这是否回答了您的问题,但您可以在 header 中放置您喜欢的任何内容 - 它不必与传递给 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);
}
关于java - 使用 SuperCSV 更改 header 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21942042/