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

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.xsdhttp://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/beanshttp://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/beanshttp://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.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsdhttp://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.xsdhttp://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.mzph.cn/news/11097.shtml

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

相关文章

elasticsearch IK分词器

说明&#xff1a;es默认的分词器对中文的识别不是特别好&#xff0c;一段话的分词是一个一个汉字&#xff0c;这显然没有达到想要的结果。 可以安装IK分词器&#xff0c;兼容中文的分词&#xff1b; IK分词器 安装 安装IK分词器&#xff0c;例如elasticsearch的容器名为es&a…

MATLAB与ROS联合仿真——控制类功能模块介绍

1、Keyboard Control &#xff08;1&#xff09;输入参数&#xff1a;无 &#xff08;2&#xff09;输出参数&#xff1a;Speed Factor为输出的速度系数&#xff08;1代表前行&#xff0c;0停止&#xff0c;-1代表后退&#xff09;&#xff0c;Turn Factor为输出的舵机系数&am…

webpack联邦模块介绍及在dumi中使用问题整理

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 前言一、ModuleFederationPlugin参数含义&#xff1f;二、如何在dumi中使用及问题整理1. 如何在dumi中使用(这个配置是好使的)2.相关问题整理2.1 问题12.2 问题2 总…

【LeetCode-中等】剑指 Offer 67. 把字符串转换成整数(详解)

题目 写一个函数 StrToInt&#xff0c;实现把字符串转换成整数这个功能。不能使用 atoi 或者其他类似的库函数。 首先&#xff0c;该函数会根据需要丢弃无用的开头空格字符&#xff0c;直到寻找到第一个非空格的字符为止。 当我们寻找到的第一个非空字符为正或者负号时&#…

【浩鲸科技】济南Java后端面经

本文目录 写在前面试题总览题目解析1.说一下SpringBoot中常用的注解2.Redis中的基本数据类型3.TCP的网络协议4.java中常见的锁5.Hashmap的底层数据结构、底层源码、扩容机制源码6.java面向对象的特点 写在前面 关于这个专栏&#xff1a; 本专栏记录一些互联网大厂、小厂的面试实…

华为HCIP第二节-------------------------ISIS

IS-IS&#xff08;Intermediate System to Intermediate System&#xff0c;中间系统到中间系统&#xff09;是ISO &#xff08;International Organization for Standardization&#xff0c;国际标准化组织&#xff09;为它的CLNP&#xff08;ConnectionLessNetwork Protocol&…

Vue 常用指令 v-on 自定义参数和事件修饰符

自定义参数就是可以在触发事件的时候传入自定义的值。 文本框&#xff0c;绑定了一个按钮事件&#xff0c;对应的逻辑是sayhi&#xff0c;现在无论按下什么按钮都会触发这个sayhi。但是实际上不是所有的按钮都会触发&#xff0c;只会限定某一些按钮&#xff0c;最常见的按钮就…

【能量管理系统( EMS )】基于粒子群算法对光伏、蓄电池等分布式能源DG进行规模优化调度研究(Matlab代码实现)

&#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜密&#xff0c;逻辑清晰&#xff0c;为了方便读者。 ⛳️座右铭&a…

MyBatis学习笔记之逆向工程

文章目录 逆向工程配置与生成QBC查询风格 所谓的逆向工程是&#xff1a;根据数据库表逆向生成的Java的pojo类、SqlMapper.xml文件、以及mapper接口类等 要完成这个工作&#xff0c;需要借助别人写好的逆向工程插件。 虽然有点经典白学&#xff0c;但好像也没不白学 思考&#x…

【爬虫案例】用Python爬取iPhone14的电商平台评论

用python爬取某电商网站的iPhone14评论数据&#xff0c; 爬取目标&#xff1a; 核心代码如下&#xff1a; 爬取到的5分好评&#xff1a; 爬取到的3分中评&#xff1a; 爬取到的1分差评&#xff1a; 所以说&#xff0c;用python开发爬虫真的很方面&#xff01; 您好&…

基于Java+Springboot+Vue的民宿管理系统(源代码+数据库)092

基于JavaSpringbootVue的民宿管理系统(源代码数据库)092 一、系统介绍 本项目前后端分离 本系统分为管理员、商家、用户三种角色 用户角色包含以下功能&#xff1a; 注册、登录、民宿信息查看、房间信息(查看/预订/评论/收藏/退订/投诉)、在线客服、房间预订管理、房间退订…

基于vue3.0实现vr全景编辑器

随着社会的不断发现&#xff0c;现实生活中有很多时候会使用到全景现实&#xff0c;比如房地产行业vr看房&#xff0c;汽车行业vr看车之类的&#xff0c;全景可视化真实还原了现场的场景&#xff0c;真正做到沉浸式体验。 现在我们基于vue3.0版本开发出了一款沉浸式的编辑器&a…

前后端项目分离开发

问题说明&#xff1a; 开发人员同时负责前端和后端代码开发&#xff0c;分工不明确开发效率低前后端代码混合在一个工程中&#xff0c;不便于管理对开发人员要求高&#xff0c;人员招聘困难 解决方法&#xff1a; 前后端分离开发 介绍 前后端分离开发&#xff0c;就是在项…

Asp.Net 6中使用Log4Net

Asp.Net 6中使用Log4Net 1. 先新建一个ASP.NET Core空项目 2. 通过Nuget包管理器安装下面两个包 log4net Microsoft.Extensions.Logging.Log4Net.AspNetCore 3. 在项目根目录下新建log4net的配置文件log4net.config&#xff0c;并将其设置为始终复制。 <?xml version&quo…

【Spring】IOC的原理

一、 IOC 的概念 Spring 的 IOC &#xff0c;即控制反转&#xff0c;所谓控制反转 —— 本来管理业务对象&#xff08;bean&#xff09;的操作是由我们程序员去做的&#xff0c;但是有了 Spring 核心容器后&#xff0c;这些 Bean 对象的创建和管理交给我们Spring容器去做了&am…

如何选择低代码/零代码平台(最全平台总结)

来谈论这个问题之前&#xff0c;我们先来看看到底什么是低代码/零代码—— 低代码 对于“低代码”的宣传其实已经很久很广泛了&#xff0c;但是争议从来都没有停止。 忘记之前在哪里看到过一个“低代码将会取代程序员”之类的说法&#xff0c;觉得很好笑&#xff0c;看了一些…

【C++】做一个飞机空战小游戏(二)——利用getch()函数实现键盘控制单个字符移动

[导读]本系列博文内容链接如下&#xff1a; 【C】做一个飞机空战小游戏(一)——使用getch()函数获得键盘码值 【C】做一个飞机空战小游戏(二)——利用getch()函数实现键盘控制单个字符移动 在【C】做一个飞机空战小游戏(一)——使用getch()函数获得键盘码值一文中介绍了如何利用…

2023年深圳杯数学建模A题影响城市居民身体健康的因素分析

2023年深圳杯数学建模 A题 影响城市居民身体健康的因素分析 原题再现&#xff1a; 以心脑血管疾病、糖尿病、恶性肿瘤以及慢性阻塞性肺病为代表的慢性非传染性疾病&#xff08;以下简称慢性病&#xff09;已经成为影响我国居民身体健康的重要问题。随着人们生活方式的改变&am…

opencv-18 什么是色彩空间?

1.什么是色彩空间类型&#xff1f; 色彩空间类型&#xff0c;也称为颜色空间类型或色彩模型&#xff0c;是一种表示图像中颜色的方式。在计算机图形学和数字图像处理中&#xff0c;有许多种色彩空间类型&#xff0c;每种类型有不同的表达方式和特点。 常见的色彩空间类型包括&a…

maven

一、为什么需要使用maven 如今我们构建一个项目需要用到很多第三方的类库 &#xff0c;例如我们在开发项目中 需要引入 这些依赖jar包 一个项目Jar包的数量之多往往让我们瞠目结舌&#xff0c;并且Jar包之间的关系非常复杂&#xff0c;一个Jar包往往又会引用其他Jar包&#x…