Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
SpringBoot-kwan
提交
fbc18c7b
S
SpringBoot-kwan
项目概览
Kwan的解忧杂货铺@新空间代码工作室
/
SpringBoot-kwan
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SpringBoot-kwan
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
fbc18c7b
编写于
2月 19, 2023
作者:
Kwan的解忧杂货铺@新空间代码工作室
🐭
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:解决版本问题
上级
ffc2bcec
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
236 addition
and
142 deletion
+236
-142
pom.xml
pom.xml
+5
-0
src/main/java/com/kwan/springbootkwan/config/CsvBatchJobConfig.java
...ava/com/kwan/springbootkwan/config/CsvBatchJobConfig.java
+83
-83
src/main/java/com/kwan/springbootkwan/controller/PersonController.java
.../com/kwan/springbootkwan/controller/PersonController.java
+59
-59
src/main/resources/application-bak2.yaml
src/main/resources/application-bak2.yaml
+76
-0
src/main/resources/application.yaml
src/main/resources/application.yaml
+13
-0
未找到文件。
pom.xml
浏览文件 @
fbc18c7b
...
@@ -129,6 +129,11 @@
...
@@ -129,6 +129,11 @@
<artifactId>
mybatis-plus-extension
</artifactId>
<artifactId>
mybatis-plus-extension
</artifactId>
<version>
3.5.1
</version>
<version>
3.5.1
</version>
</dependency>
</dependency>
<dependency>
<groupId>
io.seata
</groupId>
<artifactId>
seata-spring-boot-starter
</artifactId>
<version>
1.4.0
</version>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
<plugins>
<plugins>
...
...
src/main/java/com/kwan/springbootkwan/config/CsvBatchJobConfig.java
浏览文件 @
fbc18c7b
package
com.kwan.springbootkwan.config
;
//
package com.kwan.springbootkwan.config;
//
import
com.kwan.springbootkwan.entity.Person
;
//
import com.kwan.springbootkwan.entity.Person;
import
org.springframework.batch.core.Job
;
//
import org.springframework.batch.core.Job;
import
org.springframework.batch.core.Step
;
//
import org.springframework.batch.core.Step;
import
org.springframework.batch.core.configuration.annotation.JobBuilderFactory
;
//
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import
org.springframework.batch.core.configuration.annotation.StepBuilderFactory
;
//
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import
org.springframework.batch.core.configuration.annotation.StepScope
;
//
import org.springframework.batch.core.configuration.annotation.StepScope;
import
org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider
;
//
import org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider;
import
org.springframework.batch.item.database.JdbcBatchItemWriter
;
//
import org.springframework.batch.item.database.JdbcBatchItemWriter;
import
org.springframework.batch.item.file.FlatFileItemReader
;
//
import org.springframework.batch.item.file.FlatFileItemReader;
import
org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper
;
//
import org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper;
import
org.springframework.batch.item.file.mapping.DefaultLineMapper
;
//
import org.springframework.batch.item.file.mapping.DefaultLineMapper;
import
org.springframework.batch.item.file.transform.DelimitedLineTokenizer
;
//
import org.springframework.batch.item.file.transform.DelimitedLineTokenizer;
import
org.springframework.beans.factory.annotation.Autowired
;
//
import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.context.annotation.Bean
;
//
import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
//
import org.springframework.context.annotation.Configuration;
import
org.springframework.core.io.ClassPathResource
;
//
import org.springframework.core.io.ClassPathResource;
//
import
javax.sql.DataSource
;
//
import javax.sql.DataSource;
//
@Configuration
//
@Configuration
public
class
CsvBatchJobConfig
{
//
public class CsvBatchJobConfig {
//
//
@Autowired
//
@Autowired
JobBuilderFactory
jobBuilderFactory
;
//
JobBuilderFactory jobBuilderFactory;
@Autowired
//
@Autowired
StepBuilderFactory
stepBuilderFactory
;
//
StepBuilderFactory stepBuilderFactory;
@Autowired
//
@Autowired
DataSource
dataSource
;
//
DataSource dataSource;
//
//
@Bean
//
@Bean
@StepScope
//
@StepScope
FlatFileItemReader
<
Person
>
itemReader
()
{
//
FlatFileItemReader<Person> itemReader() {
FlatFileItemReader
<
Person
>
reader
=
new
FlatFileItemReader
<>();
//
FlatFileItemReader<Person> reader = new FlatFileItemReader<>();
reader
.
setLinesToSkip
(
1
);
//
reader.setLinesToSkip(1);
reader
.
setResource
(
new
ClassPathResource
(
"data.csv"
));
//
reader.setResource(new ClassPathResource("data.csv"));
reader
.
setLineMapper
(
new
DefaultLineMapper
<
Person
>()
{{
//
reader.setLineMapper(new DefaultLineMapper<Person>() {{
setLineTokenizer
(
new
DelimitedLineTokenizer
()
{
//
setLineTokenizer(new DelimitedLineTokenizer() {
{
//
{
setNames
(
"id"
,
"username"
,
"address"
,
"gender"
);
//
setNames("id", "username", "address", "gender");
//配置列与列之间的间隔符(将通过间隔符对每一行的数据进行切分),最后设置要映射的实体类属性即可
//
//配置列与列之间的间隔符(将通过间隔符对每一行的数据进行切分),最后设置要映射的实体类属性即可
setDelimiter
(
","
);
//
setDelimiter(",");
}
//
}
});
//
});
setFieldSetMapper
(
new
BeanWrapperFieldSetMapper
<
Person
>()
{
//
setFieldSetMapper(new BeanWrapperFieldSetMapper<Person>() {
{
//
{
setTargetType
(
Person
.
class
);
//
setTargetType(Person.class);
}
//
}
});
//
});
//
}});
//
}});
return
reader
;
//
return reader;
}
//
}
//
@Bean
//
@Bean
public
JdbcBatchItemWriter
jdbcBatchItemWriter
()
{
//
public JdbcBatchItemWriter jdbcBatchItemWriter() {
JdbcBatchItemWriter
writer
=
new
JdbcBatchItemWriter
();
//
JdbcBatchItemWriter writer = new JdbcBatchItemWriter();
writer
.
setDataSource
(
dataSource
);
//
writer.setDataSource(dataSource);
writer
.
setSql
(
"insert into person(id, username,address,gender)"
+
"values (:id, :username, :address, :gender)"
);
//
writer.setSql("insert into person(id, username,address,gender)" + "values (:id, :username, :address, :gender)");
writer
.
setItemSqlParameterSourceProvider
(
new
BeanPropertyItemSqlParameterSourceProvider
<>());
//
writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<>());
return
writer
;
//
return writer;
}
//
}
//
@Bean
//
@Bean
Step
csvStep
()
{
//
Step csvStep() {
return
stepBuilderFactory
.
get
(
"csvStep"
)
//
return stepBuilderFactory.get("csvStep")
.<
Person
,
Person
>
chunk
(
2
)
//
.<Person, Person>chunk(2)
.
reader
(
itemReader
())
//
.reader(itemReader())
.
writer
(
jdbcBatchItemWriter
())
//
.writer(jdbcBatchItemWriter())
.
build
();
//
.build();
}
//
}
//
@Bean
//
@Bean
Job
csvJob
()
{
//
Job csvJob() {
return
jobBuilderFactory
.
get
(
"csvJob"
)
//
return jobBuilderFactory.get("csvJob")
.
start
(
csvStep
())
//
.start(csvStep())
.
build
();
//
.build();
//
}
//
}
}
//
}
src/main/java/com/kwan/springbootkwan/controller/PersonController.java
浏览文件 @
fbc18c7b
package
com.kwan.springbootkwan.controller
;
//package com.kwan.springbootkwan.controller;
//
import
com.kwan.springbootkwan.entity.Person
;
//import com.kwan.springbootkwan.entity.Person;
import
com.kwan.springbootkwan.entity.User
;
//import com.kwan.springbootkwan.entity.User;
import
com.kwan.springbootkwan.service.IUserService
;
//import com.kwan.springbootkwan.service.IUserService;
import
io.swagger.annotations.Api
;
//import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiOperation
;
//import io.swagger.annotations.ApiOperation;
import
org.springframework.batch.core.Job
;
//import org.springframework.batch.core.Job;
import
org.springframework.batch.core.JobParameters
;
//import org.springframework.batch.core.JobParameters;
import
org.springframework.batch.core.launch.JobLauncher
;
//import org.springframework.batch.core.launch.JobLauncher;
import
org.springframework.beans.factory.annotation.Autowired
;
//import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.web.bind.annotation.*
;
//import org.springframework.web.bind.annotation.*;
//
import
java.util.Date
;
//import java.util.Date;
import
java.util.List
;
//import java.util.List;
//
/**
///**
* Person相关
// * Person相关
*
// *
* @author : qinyingjie
// * @author : qinyingjie
* @version : 2.2.0
// * @version : 2.2.0
* @date : 2022/12/19 16:08
// * @date : 2022/12/19 16:08
*/
// */
@Api
(
description
=
"person用户信息"
,
tags
=
"PersonController"
)
//@Api(description = "person用户信息", tags = "PersonController")
@RestController
//@RestController
@RequestMapping
(
"/person"
)
//@RequestMapping("/person")
public
class
PersonController
{
//public class PersonController {
//
@Autowired
// @Autowired
private
JobLauncher
jobLauncher
;
// private JobLauncher jobLauncher;
@Autowired
// @Autowired
private
Job
job
;
// private Job job;
//
/**
// /**
* {
// * {
* "name": "zhang san",
// * "name": "zhang san",
* "age": 24,
// * "age": 24,
* "birthday": "2022-12-19"
// * "birthday": "2022-12-19"
* }
// * }
*/
// */
@ApiOperation
(
value
=
"json返回"
,
notes
=
"json返回"
)
// @ApiOperation(value = "json返回", notes = "json返回")
@GetMapping
(
"/person"
)
// @GetMapping("/person")
public
Person
person
()
{
// public Person person() {
Person
person
=
new
Person
();
// Person person = new Person();
person
.
setUsername
(
"zhang san"
);
// person.setUsername("zhang san");
person
.
setId
(
24
);
// person.setId(24);
person
.
setAddress
(
"湖北"
);
// person.setAddress("湖北");
return
person
;
// return person;
}
// }
//
@GetMapping
(
"/hello"
)
// @GetMapping("/hello")
public
void
hello
()
{
// public void hello() {
try
{
// try {
jobLauncher
.
run
(
job
,
new
JobParameters
());
// jobLauncher.run(job, new JobParameters());
}
catch
(
Exception
e
)
{
// } catch (Exception e) {
e
.
printStackTrace
();
// e.printStackTrace();
}
// }
}
// }
}
//}
\ No newline at end of file
\ No newline at end of file
src/main/resources/application-bak2.yaml
0 → 100644
浏览文件 @
fbc18c7b
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
src/main/resources/application.yaml
浏览文件 @
fbc18c7b
...
@@ -11,6 +11,8 @@ swagger:
...
@@ -11,6 +11,8 @@ swagger:
#兼容swagger配置
#兼容swagger配置
spring
:
spring
:
application
:
name
:
spring-boot-name
#项目启动时创建数据表的 SQL 脚本,该脚本由 Spring Batch 提供
#项目启动时创建数据表的 SQL 脚本,该脚本由 Spring Batch 提供
#spring.datasource.schema=classpath:/org/springframework/batch/core/schema-mysql.sql
#spring.datasource.schema=classpath:/org/springframework/batch/core/schema-mysql.sql
# 在项目启动时执行建表 SQL
# 在项目启动时执行建表 SQL
...
@@ -53,6 +55,17 @@ spring:
...
@@ -53,6 +55,17 @@ spring:
username
:
root
username
:
root
password
:
716288qwe
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配置
mybatis-plus
:
mybatis-plus
:
configuration
:
configuration
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录