fix:解决版本问题

上级 ffc2bcec
......@@ -129,6 +129,11 @@
<artifactId>mybatis-plus-extension</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
<version>1.4.0</version>
</dependency>
</dependencies>
<build>
<plugins>
......
package com.kwan.springbootkwan.config;
import com.kwan.springbootkwan.entity.Person;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
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.batch.item.database.BeanPropertyItemSqlParameterSourceProvider;
import org.springframework.batch.item.database.JdbcBatchItemWriter;
import org.springframework.batch.item.file.FlatFileItemReader;
import org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper;
import org.springframework.batch.item.file.mapping.DefaultLineMapper;
import org.springframework.batch.item.file.transform.DelimitedLineTokenizer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import javax.sql.DataSource;
@Configuration
public class CsvBatchJobConfig {
@Autowired
JobBuilderFactory jobBuilderFactory;
@Autowired
StepBuilderFactory stepBuilderFactory;
@Autowired
DataSource dataSource;
@Bean
@StepScope
FlatFileItemReader<Person> itemReader() {
FlatFileItemReader<Person> reader = new FlatFileItemReader<>();
reader.setLinesToSkip(1);
reader.setResource(new ClassPathResource("data.csv"));
reader.setLineMapper(new DefaultLineMapper<Person>() {{
setLineTokenizer(new DelimitedLineTokenizer() {
{
setNames("id", "username", "address", "gender");
//配置列与列之间的间隔符(将通过间隔符对每一行的数据进行切分),最后设置要映射的实体类属性即可
setDelimiter(",");
}
});
setFieldSetMapper(new BeanWrapperFieldSetMapper<Person>() {
{
setTargetType(Person.class);
}
});
}});
return reader;
}
@Bean
public JdbcBatchItemWriter jdbcBatchItemWriter() {
JdbcBatchItemWriter writer = new JdbcBatchItemWriter();
writer.setDataSource(dataSource);
writer.setSql("insert into person(id, username,address,gender)" + "values (:id, :username, :address, :gender)");
writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<>());
return writer;
}
@Bean
Step csvStep() {
return stepBuilderFactory.get("csvStep")
.<Person, Person>chunk(2)
.reader(itemReader())
.writer(jdbcBatchItemWriter())
.build();
}
@Bean
Job csvJob() {
return jobBuilderFactory.get("csvJob")
.start(csvStep())
.build();
}
}
//package com.kwan.springbootkwan.config;
//
//import com.kwan.springbootkwan.entity.Person;
//import org.springframework.batch.core.Job;
//import org.springframework.batch.core.Step;
//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.batch.item.database.BeanPropertyItemSqlParameterSourceProvider;
//import org.springframework.batch.item.database.JdbcBatchItemWriter;
//import org.springframework.batch.item.file.FlatFileItemReader;
//import org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper;
//import org.springframework.batch.item.file.mapping.DefaultLineMapper;
//import org.springframework.batch.item.file.transform.DelimitedLineTokenizer;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.io.ClassPathResource;
//
//import javax.sql.DataSource;
//
//@Configuration
//public class CsvBatchJobConfig {
//
//
// @Autowired
// JobBuilderFactory jobBuilderFactory;
// @Autowired
// StepBuilderFactory stepBuilderFactory;
// @Autowired
// DataSource dataSource;
//
//
// @Bean
// @StepScope
// FlatFileItemReader<Person> itemReader() {
// FlatFileItemReader<Person> reader = new FlatFileItemReader<>();
// reader.setLinesToSkip(1);
// reader.setResource(new ClassPathResource("data.csv"));
// reader.setLineMapper(new DefaultLineMapper<Person>() {{
// setLineTokenizer(new DelimitedLineTokenizer() {
// {
// setNames("id", "username", "address", "gender");
// //配置列与列之间的间隔符(将通过间隔符对每一行的数据进行切分),最后设置要映射的实体类属性即可
// setDelimiter(",");
// }
// });
// setFieldSetMapper(new BeanWrapperFieldSetMapper<Person>() {
// {
// setTargetType(Person.class);
// }
// });
//
// }});
// return reader;
// }
//
// @Bean
// public JdbcBatchItemWriter jdbcBatchItemWriter() {
// JdbcBatchItemWriter writer = new JdbcBatchItemWriter();
// writer.setDataSource(dataSource);
// writer.setSql("insert into person(id, username,address,gender)" + "values (:id, :username, :address, :gender)");
// writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<>());
// return writer;
// }
//
// @Bean
// Step csvStep() {
// return stepBuilderFactory.get("csvStep")
// .<Person, Person>chunk(2)
// .reader(itemReader())
// .writer(jdbcBatchItemWriter())
// .build();
// }
//
// @Bean
// Job csvJob() {
// return jobBuilderFactory.get("csvJob")
// .start(csvStep())
// .build();
//
// }
//}
package com.kwan.springbootkwan.controller;
import com.kwan.springbootkwan.entity.Person;
import com.kwan.springbootkwan.entity.User;
import com.kwan.springbootkwan.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;
/**
* Person相关
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2022/12/19 16:08
*/
@Api(description = "person用户信息", tags = "PersonController")
@RestController
@RequestMapping("/person")
public class PersonController {
@Autowired
private JobLauncher jobLauncher;
@Autowired
private Job job;
/**
* {
* "name": "zhang san",
* "age": 24,
* "birthday": "2022-12-19"
* }
*/
@ApiOperation(value = "json返回", notes = "json返回")
@GetMapping("/person")
public Person person() {
Person person = new Person();
person.setUsername("zhang san");
person.setId(24);
person.setAddress("湖北");
return person;
}
@GetMapping("/hello")
public void hello() {
try {
jobLauncher.run(job, new JobParameters());
} catch (Exception e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
//package com.kwan.springbootkwan.controller;
//
//import com.kwan.springbootkwan.entity.Person;
//import com.kwan.springbootkwan.entity.User;
//import com.kwan.springbootkwan.service.IUserService;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import org.springframework.batch.core.Job;
//import org.springframework.batch.core.JobParameters;
//import org.springframework.batch.core.launch.JobLauncher;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.*;
//
//import java.util.Date;
//import java.util.List;
//
///**
// * Person相关
// *
// * @author : qinyingjie
// * @version : 2.2.0
// * @date : 2022/12/19 16:08
// */
//@Api(description = "person用户信息", tags = "PersonController")
//@RestController
//@RequestMapping("/person")
//public class PersonController {
//
// @Autowired
// private JobLauncher jobLauncher;
// @Autowired
// private Job job;
//
// /**
// * {
// * "name": "zhang san",
// * "age": 24,
// * "birthday": "2022-12-19"
// * }
// */
// @ApiOperation(value = "json返回", notes = "json返回")
// @GetMapping("/person")
// public Person person() {
// Person person = new Person();
// person.setUsername("zhang san");
// person.setId(24);
// person.setAddress("湖北");
// return person;
// }
//
// @GetMapping("/hello")
// public void hello() {
// try {
// jobLauncher.run(job, new JobParameters());
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
//}
\ No newline at end of file
server:
port: 8761
servlet:
encoding:
force: true
charset: UTF-8
enabled: true
swagger:
enable: true
#兼容swagger配置
spring:
#项目启动时创建数据表的 SQL 脚本,该脚本由 Spring Batch 提供
#spring.datasource.schema=classpath:/org/springframework/batch/core/schema-mysql.sql
# 在项目启动时执行建表 SQL
batch:
initialize-schema: always
# 禁止 Spring Batch 自动执行,在 SpringBoot 中,默认情况,当项目启动时就会执行配置好的批理操作,添加了该配置后则不会自动执行,而需要用户手动触发执行
job:
enabled: false
mail:
host: smtp.qq.com
# 发送者的邮箱账号
username: 327782001@qq.com
# 邮箱密码授权码
password: kypxnmwfniqrcbeh
properties:
mail:
smtp:
auth: true
starttls:
enable: true
required: true
redis:
database: 0 # Redis数据库索引(默认为0)
host: 120.79.36.53 #Redis服务器地址
port: 6379 # Redis服务器连接端口
password: # Redis服务器连接密码(默认为空)
jedis:
pool:
max-active: 200 # 连接池最大连接数(使用负值表示没有限制)
max-idle: 10 # 连接池中的最大空闲连接
min-idle: 0 # 连接池中的最小空闲连接
max-wait: -1 # 连接池最大阻塞等待时间(使用负值表示没有限制)
mvc:
pathmatch:
matching-strategy: ant_path_matcher
# mysql
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/kwan?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
username: root
password: 716288qwe
#mybatis-plus配置
mybatis-plus:
configuration:
map-underscore-to-camel-case: true
call-setters-on-nulls: true
auto-mapping-behavior: full
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
mapper-locations: classpath*:mapper/**/*Mapper.xml
global-config:
banner: false
# 逻辑删除配置
db-config:
id-type: AUTO
logic-delete-field: delFlag
logic-delete-value: 1
logic-not-delete-value: 0
table-underline: true
#logger配置
logging:
config: classpath:logback-spring.xml
\ No newline at end of file
......@@ -11,6 +11,8 @@ swagger:
#兼容swagger配置
spring:
application:
name: spring-boot-name
#项目启动时创建数据表的 SQL 脚本,该脚本由 Spring Batch 提供
#spring.datasource.schema=classpath:/org/springframework/batch/core/schema-mysql.sql
# 在项目启动时执行建表 SQL
......@@ -53,6 +55,17 @@ spring:
username: root
password: 716288qwe
seata:
application-id: spring-boot-name
tx-service-group: spring-boot-name-group
service:
vgroup-mapping:
spring-boot-demo-group: default
grouplist:
default: 127.0.0.1:8091
#mybatis-plus配置
mybatis-plus:
configuration:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册