javascript
springbatch读文件(flatfileitemreader)写据库(mybatisbatchitemwriter)(四) -凯发ag旗舰厅登录网址下载
文章目录
- 一、抽取顺序读取数据库公共writer
- 二、mapper配置文件
- 三、写数据库的job
- 四、继承公共commonprocesor
- 五、执行job
前言:我们在日常开发中可能会遇到写数据库,springbatch封装的也有写数据库的writer,但是我们这次做实验用的是mybatis封装的mybatisbatchitemwriter
代码已上传github上面地址:https://github.com/fadehub/spring-boot-learn/tree/master/spring-boot-springbatch
注意:本章job使用的所有实体类均是上一章springbatch读数据库(mybatispagingitemreader)(三)的实体,所以这一章
就不在一一列举了。
springbatch其它文章直通车:
springbatch读单个文件(flatfileitemreader)和写单个文件(flatfileitemwriter)(一)
springbatch顺序读取多文件(multiresourceitemreader)和顺序写文件(multiresourceitemwriter)(二)
springbatch读数据库(mybatispagingitemreader)(三)
springbatch读文件(flatfileitemreader)写据库(mybatisbatchitemwriter)(四)
springbatch 监听器之job监听器(jobexecutionlistener)和step监听器(stepexecutionlistener)(五)
springbatch 监听器之chunk监听器(chunklistener)和skip监听器(skiplistener)(六)
一、抽取顺序读取数据库公共writer
commonmybatisitemwriter继承mybatisbatchitemwriter
package com.sl.common;import org.apache.ibatis.session.sqlsessionfactory; import org.mybatis.spring.batch.mybatisbatchitemwriter;/*** 写数据库* @author shuliangzhao* @title: commonmybatisitemwriter* @projectname spring-boot-learn* @description: todo* @date 2019/9/10 19:18*/ public class commonmybatisitemwriter二、mapper配置文件
三、写数据库的job
package com.sl.config;import com.sl.common.commonfileitemreader; import com.sl.common.commonmybatisitemwriter; import com.sl.entity.cafecat; import com.sl.entity.cat; import com.sl.processor.catprocessor; import org.apache.ibatis.session.sqlsessionfactory; import org.springframework.batch.core.job; import org.springframework.batch.core.step; import org.springframework.batch.core.configuration.annotation.enablebatchprocessing; import org.springframework.batch.core.configuration.annotation.jobbuilderfactory; import org.springframework.batch.core.configuration.annotation.stepbuilderfactory; import org.springframework.batch.core.configuration.annotation.stepscope; import org.springframework.beans.factory.annotation.autowired; import org.springframework.context.annotation.bean; import org.springframework.context.annotation.configuration;/*** @author shuliangzhao* @title: cafecatconfiguration* @projectname spring-boot-learn* @description: todo* @date 2019/9/10 19:31*/ @configuration @enablebatchprocessing public class cafecatconfiguration {@autowiredprivate jobbuilderfactory jobbuilderfactory;@autowiredprivate stepbuilderfactory stepbuilderfactory;@autowiredprivate catprocessor catprocessor;@autowiredprivate sqlsessionfactory sqlsessionfactory;@beanpublic job cafecatjob() {return jobbuilderfactory.get("cafecatjob").start(cafecatstep()).build();}@beanpublic step cafecatstep() {return stepbuilderfactory.get("cafecatstep").四、继承公共commonprocesor
package com.sl.processor;import com.sl.common.commonprocessor; import com.sl.entity.cafecat; import com.sl.entity.cat; import org.springframework.batch.core.configuration.annotation.stepscope; import org.springframework.stereotype.component;/*** @author shuliangzhao* @title: catprocessor* @projectname spring-boot-learn* @description: todo* @date 2019/9/10 20:13*/ @component @stepscope public class catprocessor extends commonprocessor五、执行job
执行完job,可以查看数据库已经有数据
以上例子就是读文件和写数据库的例子。
总结
以上是凯发ag旗舰厅登录网址下载为你收集整理的springbatch读文件(flatfileitemreader)写据库(mybatisbatchitemwriter)(四)的全部内容,希望文章能够帮你解决所遇到的问题。
如果觉得凯发ag旗舰厅登录网址下载网站内容还不错,欢迎将凯发ag旗舰厅登录网址下载推荐给好友。
- 上一篇: springbatch顺序读取多文件(m
- 下一篇: springbatch 监听器之job监