How to custom Spring Batch DelimitedLineTokenizer?
来源:互联网 发布:淘宝宝贝描述模板制作 编辑:程序博客网 时间:2024/06/06 02:36
今天在用spring batch分析csv文件的时候,由于csv文件是以$进行分割的,所以需要在配置文件中添加一个属性:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:batch="http://www.springframework.org/schema/batch" xmlns:task="http://www.springframework.org/schema/task" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd"> <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> </batch:job> <bean id="cvsFileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader"> <!-- Read a csv file --> <property name="resource" value="classpath:cvs/report.csv" /> <property name="lineMapper"> <bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper"> <!-- split it --> <property name="lineTokenizer"> <bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer"> **<property name="delimiter" value="$"/>** <property name="names" value="id,docnum,pubdate,appldate,classipcr,title,pabstract,applicant,address,inventor" /> </bean> </property> <property name="fieldSetMapper"> <!-- return back to reader, rather than a mapped object. --> <!-- <bean class="org.springframework.batch.item.file.mapping.PassThroughFieldSetMapper" /> --> <!-- map to an object --> <bean class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper"> <property name="prototypeBeanName" value="report" /> </bean> </property> </bean> </property> </bean> <bean id="mysqlItemWriter" class="org.springframework.batch.item.database.JdbcBatchItemWriter"> <property name="dataSource" ref="dataSource" /> <property name="sql"> <value> <![CDATA[ insert into patent_invention(id,docnum,pubdate,appldate,classipcr,title,pabstract,applicant, address,inventor) values (:id, :docnum, :pubdate, :appldate,:classipcr,:title,:pabstract,:applicant,:address,:inventor) ]]> </value> </property> <!-- It will take care matching between object property and sql name parameter --> <property name="itemSqlParameterSourceProvider"> <bean class="org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider" /> </property> </bean></beans>
0 0
- How to custom Spring Batch DelimitedLineTokenizer?
- HOW TO Custom DSDT
- how-to-use-custom-cursors
- How to custom RedHat DVD
- How to add custom scripts
- How to do custom statistic in OPNET
- How to write your own custom Form
- How to: Work Item Tracking Custom Controls
- How to: Create a Custom List Definition
- How To Auto Complete With Custom Values
- How to create custom price in Magento?
- How to Use Custom NSAttributedString Attributes
- How to Write a Custom Swing Component
- how to make custom table cell
- how to set custom navigator title
- How to implement DynamicMBean with custom annotation
- How to: Create a Custom Action Specific to a List
- How to add custom title bar to android application
- h5中相对路径与绝对路径总结
- 手机端文字用rem有的地方会文字模糊
- KeeLoq算法源码
- STM32F103ZET6+ENC28J60+LWIP实现UDP组播
- 内存占用过高导致其他应用block住
- How to custom Spring Batch DelimitedLineTokenizer?
- 【BZOJ】1455 罗马游戏 左偏树
- RecyclerView实现下拉刷新和上拉加载更多
- Android-异常处理-Can not perform this action after onSaveInstanceState
- PHP提交含有CheckBox的表单,比对字符串是否含有相同字母
- 适应不同分辨率的对话框界面
- cpu使用过高导致其余app被block住
- Jquery的parentsUntil()、nextUntil()、sibliings()的区别
- RESTful 异常统一管理