Spring批处理xlxs文件到MySql数据库
我是SpringBatch的新手,我实现了一个cvs文件示例,其中colmun用逗号分隔 但是我有一个xlxs文件,它只包含没有分隔符的colmuns,我想在我的xlxs文件中插入数据,而不使用分隔符 这是工作报告的内容Spring批处理xlxs文件到MySql数据库,mysql,spring,spring-batch,Mysql,Spring,Spring Batch,我是SpringBatch的新手,我实现了一个cvs文件示例,其中colmun用逗号分隔 但是我有一个xlxs文件,它只包含没有分隔符的colmuns,我想在我的xlxs文件中插入数据,而不使用分隔符 这是工作报告的内容 <bean id="report" class="com.mkyong.model.Report" scope="prototype" /> <batch:job id="reportJob"> <batch:step id="step1">
<bean id="report" class="com.mkyong.model.Report" scope="prototype" />
<batch:job id="reportJob">
<batch:step id="step1">
<batch:tasklet>
<batch:chunk reader="cvsFileItemReader" writer="mysqlItemWriter"
commit-interval="2">
</batch:chunk>
</batch:tasklet>
</batch:step>
PS:在我的文件中,每列都包含值不带分隔符。如果要从使用Excel创建的.XLS或.XLSX文件中读取批处理作业的输入数据,则需要使用包含Excel ItemReader实现的Spring批处理扩展名。您需要从源代码构建jar。以下是链接: 并按如下方式使用:
<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.BeanWrapperowMapper">
<property name="targetType" value="com.your.package.Model" />
<bean>
</property>
</bean>
参考资料:我没有完全理解我看到的这个例子,但我没有看到这个例子中的spring批处理。如果你能解释更多。从第一个链接开始,您将获得关于为spring批处理扩展构建库jar的说明。将此jar添加到项目的依赖项库中。之后,您将能够使用POITEMReader使用给定的配置读取xlsx文件。
org.springframework.batch.item.file.FlatFileParseException: Parsing error at line: 1 in resource=[class path resource [cvs/report.csv]], input=[123456;139,237;37;123456]
<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.BeanWrapperowMapper">
<property name="targetType" value="com.your.package.Model" />
<bean>
</property>
</bean>