如何在 Spring 批处理中获取 FlatFileItemWriter <property name="names" values="???" /> 中的所有列名?

How to get all column names in FlatFileItemWriter <property name="names" values="???" /> in Spring Batch?

我是 Spring Batch 版本 3.0.6.RELEASE 的新手。我开发了 spring 项目,它从 mysql 数据库读取数据并写入 CSV 文件。我的数据库 table 有很多列,为了读取我需要写下所有列的名称。 获取所有列名的方法是什么?

<bean id="flatFileItemWriter" class="org.springframework.batch.item.file.FlatFileItemWriter"
        scope="step">

        <property name="resource" value="file:csv/customers.txt" />

        <property name="lineAggregator">

            <!-- An Aggregator which converts an object into delimited list of strings -->
            <bean
                class="org.springframework.batch.item.file.transform.DelimitedLineAggregator">
                <property name="delimiter" value="|" />

                <property name="fieldExtractor">
                    <!-- Extractor which returns the value of beans property through reflection -->
                    <bean class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">

                        <property name="names"
                                  value="customerNumber,customerName,contactLastName,contactFirstName,
          phone,addressLine1,addressLine2,city,state,postalCode,country,salesRepEmployeeNumber,creditLimit" />
                    </bean>
                </property>
            </bean>
        </property>
    </bean>

我不想在那里写下每一列的名称。我需要更改什么?

复杂性需要存在的地方,如果你想要一个简单的编写器配置,你不应该使用特定的 FieldExtractor,DelimitedLineAggregator will fall back to a PassThroughFieldExtractor

传递一个合适的项目,它可能会按照您期望的输出方式工作,我希望使用 FieldSet 或 Array 类型的项目获得最佳结果

PassThroughFieldExtractor.extract

A FieldSet or array will be returned as is