1 回答
TA贡献1802条经验 获得超10个赞
向方法中添加泛型
private <T> void flatFileItemReaderConfig(FlatFileItemReader<T> flatFileReader, String fileName, String incomingHeader, Class<T> clazz) {
// set delimiter as '|'
DefaultLineMapper<T> defaultLineMapper = new DefaultLineMapper<>();
DelimitedLineTokenizer delimitedLineTokenizer = new DelimitedLineTokenizer("|");
delimitedLineTokenizer.setNames(convertHeaderToEntityAttrib(fileName, incomingHeader));
defaultLineMapper.setLineTokenizer(delimitedLineTokenizer);
// convert each record into primary entity
BeanWrapperFieldSetMapper<T> beanWrapperFieldSetMapper = new BeanWrapperFieldSetMapper<>();
beanWrapperFieldSetMapper.setTargetType(clazz);
beanWrapperFieldSetMapper.setCustomEditors(getCustomFormatters());
defaultLineMapper.setFieldSetMapper(beanWrapperFieldSetMapper);
flatFileReader.setLineMapper(defaultLineMapper);
}
如果您只想将使用限制为列出的实体,请创建一个由所有具体实体 ( PrimaryEntity, ChildEntity1, ChildEntity2, ChildEntity3, ChildEntity4) 实现的通用接口实体,并将签名更改为
private <T extends Entity> void flatFileItemReaderConfig(...)
添加回答
举报