Updated README.md

This commit is contained in:
Marten Deinum
2014-09-17 12:29:35 +02:00
committed by Michael Minella
parent f05a429c16
commit 7e6b5ad5a0

View File

@@ -22,7 +22,7 @@ Configuration of both readers is the same, the difference is the used technology
Each reader takes a `resource` which is the excel file to read and a `rowMapper` which transforms the row in excel to an object which you can use in the rest of the process.
The project has 2 default `org.springframework.batch.item.excel.RowMapper` implementations.
Optionally one can also set the `skippedRowsCallback`, `linesToSkip` and `strict` property.
Optionally one can also set the `skippedRowsCallback`, `linesToSkip`, `strict` and `rowSetFactory` property.
##### skippedRowsCallback
When rows are skipped an optional `org.springframework.batch.item.excel.RowCallbackHandler` is called with the skipped row. This comes in handy when one needs to write the skipped rows to another file or create some logging.
@@ -33,17 +33,23 @@ The number of lines to skip, this applies to each sheet in the Excel file.
##### strict
By default `true`. This controls wether or not an exception is thrown if the file doesn't exists, by default an exception will be thrown.
##### rowSetFactory
For reading rows a `RowSet` abstraction is used. To construct a `RowSet` for the current `Sheet` a `RowSetFactory` is used. The `DefaultRowSetFactory` constructs a `DefaultRowSet` and `DefaultRowSetMetaData`. For construction of the latter a `ColumnNameExtractor` is needed. At the moment there are 2 implementations
- `StaticColumnNameExtractor` uses a preset list of column names.
- `RowNumberColumnNameExtractor` (**the default**) reads a given row (default 0) to determine the column names of the current sheet
### PassThroughRowMapper
Transforms the read row from excel into a `String[]`.
### DefaultRowMapper
Tries to convert the given row into an object, for this a `org.springframework.batch.item.excel.transform.RowTokenizer` and a `org.springframework.batch.item.file.mapping.FieldSetMapper` (from [the Spring Batch project](http://docs.spring.io/spring-batch/2.2.x/reference/html/readersAndWriters.html#fieldSetMapper)) is needed.
### BeanPropertyRowMapper
Uses a `BeanWrapper` to convert a given row into an object. Uses the column names of the given `RowSet` to map column to properties of the `targetType` or prototype bean.
By default the `org.springframework.batch.item.excel.transform.DefaultRowTokenizer` is used. This implementation assumes that the first row contains the column names. The column names are used to map to attributes on the object we are trying to create. How this mapping is done is configurable through a `org.springframework.batch.item.excel.transform.ColumnToAttributeConverter` implementation.
Again 2 implementations are provided by the framework
- `org.springframework.batch.item.excel.transform.PassThroughColumnToAttributeConverter`
- `org.springframework.batch.item.excel.transform.MappingColumnToAttributeConverter`
The `PassThroughColumnToAttributeConverter` simply assumes that the column name corresponds to a property on the object that is being created.
The `MappingColumnToAttributeConverter` contains a (optional) column-name to property-name mapping.
<bean id="excelReader" class="org.springframework.batch.item.excel.poi.PoiItemReader">
<property name="resource" value="/path/to/your/excel/file" />
<property name="rowMapper">
<bean class="org.springframework.batch.item.excel.mapping.BeanPropertyRowMapper">
<property name="targetType" value="com.your.package.Player" />
<bean>
</property>
</bean>