Spring Batch教程(三)示例:从mysql中读取数据写入文本和从多个文本中读取内容写入mysql

news2024/9/23 19:24:57

Spring batch 系列文章

Spring Batch教程(一) 简单的介绍以及通过springbatch将xml文件转成txt文件
Spring Batch教程(二)示例:将txt文件转成xml文件以及读取xml文件内容存储到数据库mysql
Spring Batch教程(三)示例:从mysql中读取数据写入文本和从多个文本中读取内容写入mysql
Spring Batch教程(四)tasklet使用示例:spring batch的定时任务使用
Spring Batch教程(五)spring boot实现batch功能注解示例:读写文本文件
Spring Batch教程(六)spring boot实现batch功能注解示例:读文件写入mysql


文章目录

  • Spring batch 系列文章
  • 一、示例1:从mysql中读取数据写入txt文件
    • 1、maven依赖
    • 2、创建mysql 表并插入数据
    • 3、PersonInfo bean
    • 4、建立RowMapper
    • 5、创建ItemProcessor实现类
    • 6、添加Job listener(JobExecutionListener)
    • 7、进行job的配置
      • 1)、job配置
      • 2)、数据源配置
    • 8、创建一个运行job的main类
    • 9、验证
      • 1)、控制台输出
      • 2)、程序结果输出
  • 二、示例2:从多数据源文件读取写入mysql
    • 1、maven依赖
    • 2、创建表
    • 3、PersonInfo bean
    • 4、建立FieldSetMapper
    • 5、创建ItemProcessor实现类
    • 6、添加Job listener(JobExecutionListener)
    • 7、进行job的配置
      • 1)、数据源配置
      • 2)、hibernate配置
      • 3)、job配置
    • 8、创建一个运行job的main类
    • 9、准备测试数据
    • 10、验证
      • 1)、控制台输出
      • 2)、程序结果输出


本文介绍了2个示例,即从mysql中读取数据写入文本和从多个文本中读取内容写入mysql。
本文使用的是jdk版本,最新版本的spring core和springb batch用不了。

一、示例1:从mysql中读取数据写入txt文件

1、maven依赖

		<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<springframework.version>5.2.25.RELEASE</springframework.version>
		<joda-time.version>2.12.5</joda-time.version>
		<mysql.connector.version>5.1.31</mysql.connector.version>
		<springbatch.version>4.2.8.RELEASE</springbatch.version>

	</properties>
	<dependencies>
		<dependency>
			<groupId>org.springframework.batch</groupId>
			<artifactId>spring-batch-core</artifactId>
			<version>${springbatch.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework.batch</groupId>
			<artifactId>spring-batch-infrastructure</artifactId>
			<version>${springbatch.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>${springframework.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-oxm</artifactId>
			<version>${springframework.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-jdbc</artifactId>
			<version>${springframework.version}</version>
		</dependency>
		<dependency>
			<groupId>joda-time</groupId>
			<artifactId>joda-time</artifactId>
			<version>${joda-time.version}</version>
		</dependency>
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>${mysql.connector.version}</version>
		</dependency>
	</dependencies>



2、创建mysql 表并插入数据

DROP TABLE IF EXISTS `personinfo`;
CREATE TABLE `personinfo`  (
  `name` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `birthday` varchar(15) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `salary` double NOT NULL
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of personinfo
-- ----------------------------
INSERT INTO `personinfo` VALUES ('alanchanchn', '1985-02-01', 76);
INSERT INTO `personinfo` VALUES ('alan', '1979-09-01', 91.5);
INSERT INTO `personinfo` VALUES ('chan', '1993-03-01', 92);
INSERT INTO `personinfo` VALUES ('alanchan', '1995-08-01', 83);

SET FOREIGN_KEY_CHECKS = 1;

3、PersonInfo bean

import lombok.Data;

/**
 * @author alanchan
 *
 */
@Data
public class PersonInfo {
	private String name;
	private String birthday;
	private double salary;
}

4、建立RowMapper

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import com.win.mysql2xml.bean.PersonInfo;

/**
 * 
 * @author alanchan
 *
 */
public class PersonInfoRowMapper implements RowMapper<PersonInfo> {

	public PersonInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
		PersonInfo personInfo = new PersonInfo();
		personInfo.setName(rs.getString("name"));
		personInfo.setBirthday(rs.getString("birthday"));
		personInfo.setSalary(rs.getDouble("salary"));

		return personInfo;
	}

}

5、创建ItemProcessor实现类

本示例仅仅是过滤一下,salary小于77的设置为salary*1.3。

import org.springframework.batch.item.ItemProcessor;

import com.win.mysql2xml.bean.PersonInfo;

/**
 * 
 * @author alanchan
 *
 */
public class PersonInfoItemProcessor implements ItemProcessor<PersonInfo, PersonInfo> {

	public PersonInfo process(PersonInfo personInfo) throws Exception {
		System.out.println("Processing result :" + personInfo);

		if (personInfo.getSalary() < 77) {

			PersonInfo tempPersonInfo = new PersonInfo();
			tempPersonInfo.setName(personInfo.getName());
			tempPersonInfo.setBirthday(personInfo.getBirthday());
			tempPersonInfo.setSalary(personInfo.getSalary() * 1.3);
			personInfo = tempPersonInfo;
		}

		return personInfo;
	}

}

6、添加Job listener(JobExecutionListener)

import java.util.List;

import org.joda.time.DateTime;
//import org.joda.time.DateTime;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionListener;

/**
 * 
 * @author alanchan
 *
 */
public class PersonInfoJobListener implements JobExecutionListener {

	private DateTime startTime, stopTime;

	public void beforeJob(JobExecution jobExecution) {
		startTime = new DateTime();
		System.out.println("job开始 at :" + startTime);
	}

	public void afterJob(JobExecution jobExecution) {
		stopTime = new DateTime();
		System.out.println("job结束 at :" + stopTime);
		System.out.println("任务耗时(毫秒) :" + getTimeInMillis(startTime, stopTime));

		if (jobExecution.getStatus() == BatchStatus.COMPLETED) {
			System.out.println("job任务完成");
			// Here you can perform some other business logic like cleanup
		} else if (jobExecution.getStatus() == BatchStatus.FAILED) {
			System.out.println("job任务异常如下 ");
			List<Throwable> exceptionList = jobExecution.getAllFailureExceptions();
			for (Throwable th : exceptionList) {
				System.err.println("异常 :" + th.getLocalizedMessage());
			}
		}
	}

	private long getTimeInMillis(DateTime start, DateTime stop) {
		return stop.getMillis() - start.getMillis();
	}

}

7、进行job的配置

1)、job配置

文件位置:/sping-batch/src/main/resources/spring-batch-context4.xml

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:batch="http://www.springframework.org/schema/batch"
	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-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
        
	<import resource="classpath:context-datasource.xml"/>
	<!-- JobRepository and JobLauncher are configuration/setup classes -->
	<bean id="jobRepository"		class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean" />

	<bean id="jobLauncher"		class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
		<property name="jobRepository" ref="jobRepository" />
	</bean>

	<!-- ItemReader which reads from database and returns the row mapped by        rowMapper -->
    <bean id="databaseItemReader"          class="org.springframework.batch.item.database.JdbcCursorItemReader">
        <property name="dataSource" ref="dataSource" />
        <property name="sql"                  value="SELECT name,birthday,salary FROM `personinfo`" />
        <property name="rowMapper">
            <bean class="com.win.mysql2xml.PersonInfoRowMapper" />
        </property>
    </bean>


    <!-- ItemWriter writes a line into output flat file -->
    <bean id="flatFileItemWriter" class="org.springframework.batch.item.file.FlatFileItemWriter"          scope="step">
        <property name="resource" value="file:d:/personInfo.txt" />
        <property name="lineAggregator">
            <!-- An Aggregator which converts an object into delimited list of strings -->
            <bean                    class="org.springframework.batch.item.file.transform.DelimitedLineAggregator">
                <property name="delimiter" value="|" />
                <property name="fieldExtractor">
                    <!-- Extractor which returns the value of beans property through reflection -->
                    <bean                            class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
                        <property name="names" value="name,birthday,salary" />
                    </bean>
                </property>
            </bean>
        </property>
    </bean>

    <!-- Optional JobExecutionListener to perform business logic before and after the job -->
    <bean id="jobListener" class="com.win.mysql2xml.PersonInfoJobListener" />

    <!-- Optional ItemProcessor to perform business logic/filtering on the input records -->
    <bean id="itemProcessor" class="com.win.mysql2xml.PersonInfoItemProcessor" />

    <!-- Step will need a transaction manager -->
    <bean id="transactionManager"          class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />

    <!-- Actual Job -->
    <batch:job id="personInfoJob">
        <batch:step id="step1">
            <batch:tasklet transaction-manager="transactionManager">
                <batch:chunk reader="databaseItemReader" writer="flatFileItemWriter"                             processor="itemProcessor" commit-interval="10" />
            </batch:tasklet>
        </batch:step>
        <batch:listeners>
            <batch:listener ref="jobListener" />
        </batch:listeners>
    </batch:job>

</beans>

2)、数据源配置

文件位置:/sping-batch/src/main/resources/context-datasource.xml

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:batch="http://www.springframework.org/schema/batch" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://192.168.10.44:3306/test" />
        <property name="username" value="root" />
        <property name="password" value="1234" />
    </bean>

</beans>

8、创建一个运行job的main类


import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionException;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 
 * @author alanchan
 *
 */
public class App {
	@SuppressWarnings("resource")
	public static void main(String areg[]) {

		ApplicationContext context = new ClassPathXmlApplicationContext("spring-batch-context4.xml");

		JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
		Job job = (Job) context.getBean("personInfoJob");

		try {
			JobExecution execution = jobLauncher.run(job, new JobParameters());
			System.out.println("Job执行状态 : " + execution.getStatus());

		} catch (JobExecutionException e) {
			System.out.println("Job 执行失败");
			e.printStackTrace();
		}
	}
}

9、验证

运行程序 ,查看输出文件内以及控制台内容

1)、控制台输出

job开始 at :2023-07-21T10:49:44.683+08:00
Processing result :PersonInfo(name=alanchanchn, birthday=1985-02-01, salary=76.0)
Processing result :PersonInfo(name=alan, birthday=1979-09-01, salary=91.5)
Processing result :PersonInfo(name=chan, birthday=1993-03-01, salary=92.0)
Processing result :PersonInfo(name=alanchan, birthday=1995-08-01, salary=83.0)
job结束 at :2023-07-21T10:49:44.918+08:00
任务耗时(毫秒) :235
job任务完成
Job执行状态 : COMPLETED

2)、程序结果输出

在这里插入图片描述

二、示例2:从多数据源文件读取写入mysql

1、maven依赖

在这里插入代码片

2、创建表

DROP TABLE IF EXISTS `personinfo`;
CREATE TABLE `personinfo`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `salary` double(10, 2) NOT NULL,
  `birthday` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

3、PersonInfo bean

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import lombok.Data;

/**
 * @author alanchan
 *
 */
@Data
@Entity
@Table(name = "personinfo")
public class PersonInfo {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private int id;
	@Column(name = "name", nullable = false)
	private String name;
	@Column(name = "birthday", nullable = false)
	private String birthday;
	@Column(name = "salary", nullable = false)
	private double salary;
}

4、建立FieldSetMapper

import org.springframework.batch.item.file.mapping.FieldSetMapper;
import org.springframework.batch.item.file.transform.FieldSet;
import org.springframework.validation.BindException;

import com.win.multireaderhibernatewriter.bean.PersonInfo;

/**
 * 
 * @author alanchan
 *
 */
public class PersonInfoFieldSetMapper implements FieldSetMapper<PersonInfo> {

	public PersonInfo mapFieldSet(FieldSet fieldSet) throws BindException {
		PersonInfo personInfo = new PersonInfo();
		personInfo.setName(fieldSet.readString(0));
		personInfo.setBirthday(fieldSet.readString(1));
		personInfo.setSalary(fieldSet.readDouble(2));
		return personInfo;
	}

}

5、创建ItemProcessor实现类

import org.springframework.batch.item.ItemProcessor;

import com.win.multireaderhibernatewriter.bean.PersonInfo;

/**
 * 
 * @author alanchan
 *
 */
public class PersonInfoItemProcessor implements ItemProcessor<PersonInfo, PersonInfo> {

	public PersonInfo process(PersonInfo personInfo) throws Exception {
		System.out.println("Processing result :" + personInfo);

		if (personInfo.getSalary() < 60) {
			PersonInfo tempPersonInfo = new PersonInfo();
			tempPersonInfo.setName(personInfo.getName());
			tempPersonInfo.setBirthday(personInfo.getBirthday());
			tempPersonInfo.setSalary(personInfo.getSalary() * 1.5);
			personInfo = tempPersonInfo;
		}

		return personInfo;
	}
}

6、添加Job listener(JobExecutionListener)

import java.util.List;

import org.joda.time.DateTime;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionListener;

/**
 * 
 * @author chenw
 *
 */
public class PersonInfoJobListener implements JobExecutionListener {

	private DateTime startTime, stopTime;

	public void beforeJob(JobExecution jobExecution) {
		startTime = new DateTime();
		System.out.println("job开始 at :" + startTime);
	}

	public void afterJob(JobExecution jobExecution) {
		stopTime = new DateTime();
		System.out.println("job结束 at :" + stopTime);
		System.out.println("任务耗时(毫秒) :" + getTimeInMillis(startTime, stopTime));

		if (jobExecution.getStatus() == BatchStatus.COMPLETED) {
			System.out.println("job任务完成");
			// Here you can perform some other business logic like cleanup
		} else if (jobExecution.getStatus() == BatchStatus.FAILED) {
			System.out.println("job任务异常如下 ");
			List<Throwable> exceptionList = jobExecution.getAllFailureExceptions();
			for (Throwable th : exceptionList) {
				System.err.println("异常 :" + th.getLocalizedMessage());
			}
		}
	}

	private long getTimeInMillis(DateTime start, DateTime stop) {
		return stop.getMillis() - start.getMillis();
	}

}

7、进行job的配置

1)、数据源配置

文件位置:/sping-batch/src/main/resources/context-datasource2.xml

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:batch="http://www.springframework.org/schema/batch"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">

	<bean id="dataSource"		class="com.mchange.v2.c3p0.ComboPooledDataSource"		destroy-method="close">
        <property name="driverClass" value="com.mysql.jdbc.Driver" />
        <property name="jdbcUrl" value="jdbc:mysql://192.168.10.44:3306/test" />
        <property name="user" value="root" />
        <property name="password" value="1234" />
	</bean>

</beans>

2)、hibernate配置

文件位置:/sping-batch/src/main/resources/context-model.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
                http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
                http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"
       default-autowire="byName"  default-init-method="init">

    <import resource="classpath:context-datasource2.xml"/>

    <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean" >
        <property name="dataSource" ref="dataSource"/>
        <property name="packagesToScan">
            <list>
                <value>com.win.multireaderhibernatewriter.bean</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop> 
                <!--     <prop key="hibernate.format_sql">true</prop> -->
            </props>
        </property>
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager" />
    <tx:annotation-driven transaction-manager="transactionManager"/>

</beans>

3)、job配置

文件位置:/sping-batch/src/main/resources/spring-batch-context5.xml

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:batch="http://www.springframework.org/schema/batch"
	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-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
        
	<import resource="classpath:context-model.xml"/>
	<!-- JobRepository and JobLauncher are configuration/setup classes -->
	<bean id="jobRepository"		class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean" />

	<bean id="jobLauncher"		class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
		<property name="jobRepository" ref="jobRepository" />
	</bean>
	
		
	<bean id="multiResourceItemReader" class="org.springframework.batch.item.file.MultiResourceItemReader">
        <property name="resources" value="classpath:testmultireader/personinfo*.txt" />
        <property name="delegate" ref="flatFileItemReader" />
    </bean>

	<!-- ItemReader reads a complete line one by one from input file -->
    <bean id="flatFileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader"  scope="step">
        <property name="lineMapper">
            <bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
                <property name="fieldSetMapper">
                    <!-- Mapper which maps each individual items in a record to properties in POJO -->
                    <bean class="com.win.multireaderhibernatewriter.PersonInfoFieldSetMapper" />
                </property>

                <property name="lineTokenizer">
                    <!-- A tokenizer class to be used when items in input record are separated by specific characters -->
                    <bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
                        <property name="delimiter" value="|" />
                    </bean>
                </property>
            </bean>
        </property>
    </bean>
    
    <!-- ItemWriter which writes data to database -->
    <bean id="databaseItemWriter" class="org.springframework.batch.item.database.HibernateItemWriter">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
    <!-- Optional ItemProcessor to perform business logic/filtering on the input records -->
    <bean id="itemProcessor" class="com.win.multireaderhibernatewriter.PersonInfoItemProcessor" />
    
    <!-- Optional JobExecutionListener to perform business logic before and after the job -->
    <bean id="jobListener" class="com.win.multireaderhibernatewriter.PersonInfoJobListener" />
    
    <!-- Actual Job -->
    <batch:job id="personInfoJob">
        <batch:step id="step1">
            <batch:tasklet transaction-manager="transactionManager">
                <batch:chunk reader="multiResourceItemReader" writer="databaseItemWriter"                             processor="itemProcessor" commit-interval="10" />
            </batch:tasklet>
        </batch:step>
        <batch:listeners>
            <batch:listener ref="jobListener" />
        </batch:listeners>
    </batch:job>
    
</beans>

8、创建一个运行job的main类


import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionException;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 
 * @author alanchan
 *
 */
public class App {
	@SuppressWarnings("resource")
	public static void main(String areg[]) {
		ApplicationContext context = new ClassPathXmlApplicationContext("spring-batch-context5.xml");

		JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
		Job job = (Job) context.getBean("personInfoJob");

		try {
			JobExecution execution = jobLauncher.run(job, new JobParameters());
			System.out.println("Job 执行状态  : " + execution.getStatus());

		} catch (JobExecutionException e) {
			System.out.println("Job 失败");
			e.printStackTrace();
		}
	}
}

9、准备测试数据

文件目录位置:/sping-batch/src/main/resources/testmultireader
数据源文件都在该部目录下

  • /sping-batch/src/main/resources/testmultireader/personinfo-1.txt
alanchanchn|1985-02-01|98.8
alan|1979-09-01|91.5

  • /sping-batch/src/main/resources/testmultireader/personinfo-2.txt
zhangsan|1998-03-01|92.0
lisi|1995-08-01|60
  • /sping-batch/src/main/resources/testmultireader/personinfo-3.txt
wangking|1989-04-01|18.0
tony|1995-08-01|86.0
  • /sping-batch/src/main/resources/testmultireader/personinfo-4.txt
zhaoqin|1997-03-01|36.0
sunmonkey|1999-08-01|23.0

10、验证

1)、控制台输出

job开始 at :2023-07-21T13:00:47.780+08:00
Processing result :PersonInfo(id=0, name=alanchanchn, birthday=1985-02-01, salary=98.8)
Processing result :PersonInfo(id=0, name=alan, birthday=1979-09-01, salary=91.5)
Processing result :PersonInfo(id=0, name=zhangsan, birthday=1998-03-01, salary=92.0)
Processing result :PersonInfo(id=0, name=lisi, birthday=1995-08-01, salary=60.0)
Processing result :PersonInfo(id=0, name=wangking, birthday=1989-04-01, salary=18.0)
Processing result :PersonInfo(id=0, name=tony, birthday=1995-08-01, salary=86.0)
Processing result :PersonInfo(id=0, name=zhaoqin, birthday=1997-03-01, salary=36.0)
Processing result :PersonInfo(id=0, name=sunmonkey, birthday=1999-08-01, salary=23.0)
Hibernate: insert into personinfo (birthday, name, salary) values (?, ?, ?)
Hibernate: insert into personinfo (birthday, name, salary) values (?, ?, ?)
Hibernate: insert into personinfo (birthday, name, salary) values (?, ?, ?)
Hibernate: insert into personinfo (birthday, name, salary) values (?, ?, ?)
Hibernate: insert into personinfo (birthday, name, salary) values (?, ?, ?)
Hibernate: insert into personinfo (birthday, name, salary) values (?, ?, ?)
Hibernate: insert into personinfo (birthday, name, salary) values (?, ?, ?)
Hibernate: insert into personinfo (birthday, name, salary) values (?, ?, ?)
job结束 at :2023-07-21T13:00:48.044+08:00
任务耗时(毫秒) :264
job任务完成
Job 执行状态  : COMPLETED

2)、程序结果输出

在这里插入图片描述

以上,介绍了2个示例,即从mysql中读取数据写入文本和从多个文本中读取内容写入mysql。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/801397.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

在CSDN的几年,我的Python书籍,第三次重印了!

大家好&#xff0c;我是黄伟&#x1f92d; 我的书籍《快学Python&#xff1a;自动化办公轻松实战》第3次重印了&#xff0c;感谢大家的支持。 这本书干货多多&#xff0c;零基础教你Python自动化办公&#xff0c;让你工作效率提升10倍&#xff0c;提前1小时下班。 因此&#…

2018年全国硕士研究生入学统一考试管理类专业学位联考写作试题——解析版

2018年1月真题 四、写作&#xff1a;第56~57小题&#xff0c;共65分。其中论证有效性分析30 分&#xff0c;论说文35分。 56.论证有效性分析&#xff1a; 分析下述论证中存在的缺陷和漏洞&#xff0c;选择若干要点&#xff0c;写一篇600字左右的文章&#xff0c;对该论证的有…

「开源项目」现代化开源Linux服务器运维管理面板-1Panel

1Panel 基本介绍 1Panel 是新一代的 Linux 服务器运维管理面板 产品优势 快速建站&#xff1a;深度集成 Wordpress 和 Halo&#xff0c;域名绑定、SSL 证书配置等一键搞定&#xff1b; 高效管理&#xff1a;通过 Web 端轻松管理 Linux 服务器&#xff0c;包括应用管理、主机监控…

二分图算法(染色法 匈牙利算法)

目录 二分图算法总览二分图的概念1.二分图的定义2.二分图的特点3.二分图的应用 染色法&#xff08;判断二分图&#xff09;算法步骤算法运用染色法判定二分图 匈牙利算法&#xff08;计算二分图的最大匹配&#xff09;二分图的匹配算法步骤算法应用二分图的最大匹配 二分图算法…

Jmeter并发测试

基本步骤 1、新建线程组 测试计划右键——>添加——>线程&#xff08;用户&#xff09;——>线程组 2、 添加HTTP请求 线程组右键——>添加——>取样器——>HTTP请求 3、 添加HTTP信息头管理器 线程组右键——>添加——>配置元件——>HTTP信息头…

【观察】以超融合创新架构,加速企业应用现代化

我们知道&#xff0c;数字化转型的不断加速&#xff0c;核心就是应用的加速。在整个数字化体系中&#xff0c;软件应用是让一切发挥价值的落地路径。在应用发挥能力之前&#xff0c;企业需要进行大量软硬件准备以及应用开发工作&#xff1b;在应用开始发挥能力之&#xff0c;企…

牛客小白月赛75F题解

文章目录 [ 打牌](https://ac.nowcoder.com/acm/contest/60063/F)问题建模问题分析代码 打牌 问题建模 给出三个长度为3的字符串&#xff0c;每个字符串仅由’w’,‘i’,‘n’三种字符组成&#xff0c;以及回合数n&#xff0c;每一个回合每一个字符串选择一个字符向其下一个字…

【Android】底层逻辑深入了解(学习笔记)(未完)

step by step. 目录 init启动 Zygote进程&#xff1a; SystemServer处理过程 Binder&#xff1a; Launcher启动过程 Android系统启动流程 四大组件 Activity Service BroadcastReceiver广播 ContentProvider内容提供者&#xff08;进程内和进程间的数据共享&#xff…

Latex | 使用MATLAB生成.eps矢量图并导入Latex中的方法

一、问题描述 用Latex时写paper时&#xff0c;要导入MATLAB生成的图进去 二、解决思路 &#xff08;1&#xff09;在MATLAB生成图片的窗口中&#xff0c;导出.eps矢量图 &#xff08;2&#xff09;把图上传到overleaf的目录 &#xff08;3&#xff09;在文中添加相应代码 三…

深度学习100例 | 第31天-卷积神经网络(DenseNet)识别生活物品

&#x1f680; 我的环境&#xff1a; 语言环境&#xff1a;Python3.6.5编译器&#xff1a;jupyter notebook深度学习环境&#xff1a;TensorFlow2.4.1显卡&#xff08;GPU&#xff09;&#xff1a;NVIDIA GeForce RTX 3080数据&#xff1a;&#x1f4cc;【传送门】 &#x1f…

Gradle和Maven的区别

Gradle和Maven 当涉及到构建和管理项目时&#xff0c;Gradle和Maven是两个非常流行的选项。本文将讨论Gradle和Maven之间的区别以及它们的配置信息差异。 1. Gradle和Maven的区别 1.1 构建脚本语言 Maven使用XML作为构建脚本语言&#xff0c;而Gradle使用基于Groovy的DSL&…

HashMap查找

文章目录 1 哈希表的基本概念1.1 两个例子1.2 如何查找1.3 若干术语 2 哈希函数的构造方法2.1 直接定址法2.2 除留余数法 3 处理冲突的方法3.1 开放地址法3.1.1 线性探测法3.1.2 二次探测法3.1.3 伪随机探测法 3.2 链地址法&#xff08;拉链法&#xff09;3.2.1 创建步骤3.2.2 …

STM32-风速传感器(ADC)

目录 0 说明 1 传感器介绍 2 代码说明 2.1 ADC.c 2.2 adc.h 2.3 main.c 0 说明 本篇文章主要是说明怎么使用STM32单片机读取风速传感器采集到的数据&#xff0c;读取方式是ADC&#xff0c;并且附带着STM32所需要的全部代码&#xff0c;所使用的风速传感器如下图所示。 附&am…

Redis—相关背景

Redis—相关背景 &#x1f50e;Redis—特性In-memory data structures—在内存中存储数据Programmability—可编程性Extensibility—可扩展性Persistence—持久化Clustering—集群High availability—高可用 &#x1f50e;Redis 为什么快&#x1f50e;Redis 的使用场景Real-tim…

看看ChatGPT的Embedding接口都完成哪些任务

调用Embedding接口完成文本分类 前面博客介绍了如何调用ChatGPT的Embedding接口完成文本聚类任务&#xff0c;实现过程入下图所示&#xff1a; 除了完成文本分类&#xff0c;调用Embedding接口还可完成聚类任务。 调用Embedding接口完成聚类任务 聚类任务是一种无监督学习任…

tinymce实现将word中内容(文字图片等)直接粘贴至编辑器中——利用插件tinymce-powerpaste-plugin

TinyMCE是一款易用、且功能强大的所见即所得的富文本编辑器。同类程序有&#xff1a;UEditor、Kindeditor、Simditor、CKEditor、wangEditor、Suneditor、froala等等。 TinyMCE的优势&#xff1a; 开源可商用&#xff0c;基于LGPL2.1 插件丰富&#xff0c;自带插件基本涵盖日常…

活字格性能优化技巧——如何利用数据库主键提升访问性能

大家都知道&#xff0c;活字格作为企业级低代码开发平台&#xff0c;拥有6大引擎&#xff0c;3大能力&#xff0c;能够高效落地企业级应用。在每年的应用大赛中也能看到很多格友利用活字格做了很多复杂的应用&#xff0c;例如2021年企业级低代码应用大赛中宁波聚轩利用活字格做…

vue使用qrcodejs2-fix或者qrcodejs2插件生成二维码

1. vue2安装 npm i qrcodejs2 1.1. vue3安装 npm install qrcodejs2-fix 2. 组件中引入并封装成公共组件&#xff0c;vue3版 <template><!-- 二维码生成 --><div class"body-div"><div style"width: 100%;height: 100%;" :id&quo…

誉天程序员-2301-3-day05

文章目录 知识回归1、单点登录SSO single sign on&#xff08;面试必考&#xff0c;10分&#xff09;2、Vue重大的扩展&#xff0c;Vue框架越来越完善&#xff0c;Vuex状态管理&#xff08;共享数据&#xff09; 全局守卫嵌套路由 知识回归 1、单点登录SSO single sign on&…

Vue2基础七、refnextTick自定义指令

零、文章目录 Vue2基础七、ref&nextTick&自定义指令 1、ref **作用&#xff1a;**利用 ref 和 $refs 可以用于 获取 dom 元素, 或 组件实例**特点&#xff1a;**查找范围 → 当前组件内 (更精确稳定)&#xff0c;用document.querySelect(‘.box’) 获取的是整个页面…