2

I am new to Spring Batch version 3.0.6.RELEASE. I developed spring project which reads data from mysql database and writes to CSV file. My database table has many columns and in order to read that I need to write all columns names. What is the way to get all columns name in ?

<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>

I don't want to write each column names there. What do I need to change?

  • Why do you do not want to write the column names there? what do you Want to achieve? – Michael Pralow Apr 03 '16 at 19:34
  • The fact that My table has more than 20 fields and sometimes it gets cumbersome to write all those fields, do we've any chance to get all fields like * we do in select ? –  Apr 03 '16 at 19:37

1 Answers1

0

somewhere the complexity needs to live, if you want a simple writer configuration you should not use a specific FieldExtractor, the DelimitedLineAggregator will fall back to a PassThroughFieldExtractor

pass a suitable item and it might work the way you expect the output, i expect the best result with an item of type FieldSet or Array

see PassThroughFieldExtractor.extract

A FieldSet or array will be returned as is

Michael Pralow
  • 6,560
  • 2
  • 30
  • 46