diff --git a/pom.xml b/pom.xml index ea258957e8fe635c3eea71009f97c5c246c2d7b8..49534a14c38ba8e56ddd8deef9f168f60efc09f7 100644 --- a/pom.xml +++ b/pom.xml @@ -129,6 +129,11 @@ mybatis-plus-extension 3.5.1 + + io.seata + seata-spring-boot-starter + 1.4.0 + diff --git a/src/main/java/com/kwan/springbootkwan/config/CsvBatchJobConfig.java b/src/main/java/com/kwan/springbootkwan/config/CsvBatchJobConfig.java index 96a55253a468c580264c37dc9cc187adf48a1eca..a72053dbe48b57d4e6bdc7818d4f8c858af66d16 100644 --- a/src/main/java/com/kwan/springbootkwan/config/CsvBatchJobConfig.java +++ b/src/main/java/com/kwan/springbootkwan/config/CsvBatchJobConfig.java @@ -1,83 +1,83 @@ -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 itemReader() { - FlatFileItemReader reader = new FlatFileItemReader<>(); - reader.setLinesToSkip(1); - reader.setResource(new ClassPathResource("data.csv")); - reader.setLineMapper(new DefaultLineMapper() {{ - setLineTokenizer(new DelimitedLineTokenizer() { - { - setNames("id", "username", "address", "gender"); - //配置列与列之间的间隔符(将通过间隔符对每一行的数据进行切分),最后设置要映射的实体类属性即可 - setDelimiter(","); - } - }); - setFieldSetMapper(new BeanWrapperFieldSetMapper() { - { - 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") - .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 itemReader() { +// FlatFileItemReader reader = new FlatFileItemReader<>(); +// reader.setLinesToSkip(1); +// reader.setResource(new ClassPathResource("data.csv")); +// reader.setLineMapper(new DefaultLineMapper() {{ +// setLineTokenizer(new DelimitedLineTokenizer() { +// { +// setNames("id", "username", "address", "gender"); +// //配置列与列之间的间隔符(将通过间隔符对每一行的数据进行切分),最后设置要映射的实体类属性即可 +// setDelimiter(","); +// } +// }); +// setFieldSetMapper(new BeanWrapperFieldSetMapper() { +// { +// 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") +// .chunk(2) +// .reader(itemReader()) +// .writer(jdbcBatchItemWriter()) +// .build(); +// } +// +// @Bean +// Job csvJob() { +// return jobBuilderFactory.get("csvJob") +// .start(csvStep()) +// .build(); +// +// } +//} diff --git a/src/main/java/com/kwan/springbootkwan/controller/PersonController.java b/src/main/java/com/kwan/springbootkwan/controller/PersonController.java index 47a38c3135a0d53a6be8b9f458f59a04284534c9..bf567fbcef5302f643bb868788c384cc5a8e66bc 100644 --- a/src/main/java/com/kwan/springbootkwan/controller/PersonController.java +++ b/src/main/java/com/kwan/springbootkwan/controller/PersonController.java @@ -1,59 +1,59 @@ -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 diff --git a/src/main/resources/application-bak2.yaml b/src/main/resources/application-bak2.yaml new file mode 100644 index 0000000000000000000000000000000000000000..a8b9276aaf8799e584250bbc74a27a002bf3e4d0 --- /dev/null +++ b/src/main/resources/application-bak2.yaml @@ -0,0 +1,76 @@ +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 diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index a8b9276aaf8799e584250bbc74a27a002bf3e4d0..abae2ce144438875d03a3a7b153437df018e213f 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -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: