Skip to content

Commit 0b557c3

Browse files
authored
Merge pull request #1 from wuyouzhuguli/master
合并
2 parents 1415ead + f630cb9 commit 0b557c3

File tree

112 files changed

+4085
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+4085
-2
lines changed

18.Spring-Boot-Jackson/src/main/java/com/example/controller/TestJsonController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public String readJsonString() {
7070
@ResponseBody
7171
public String readJsonAsObject() {
7272
try {
73-
String json = "{\"user-name\":\"mrbird\"}";
73+
String json = "{\"userName\":\"mrbird\"}";
7474
User user = mapper.readValue(json, User.class);
7575
String name = user.getUserName();
7676
return name;

67.spring-batch-start/pom.xml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.2.5.RELEASE</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>cc.mrbird</groupId>
12+
<artifactId>spring-batch-start</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>spring-batch-start</name>
15+
<description>Demo project for Spring Boot</description>
16+
17+
<properties>
18+
<java.version>1.8</java.version>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter-batch</artifactId>
25+
</dependency>
26+
27+
<dependency>
28+
<groupId>mysql</groupId>
29+
<artifactId>mysql-connector-java</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-jdbc</artifactId>
34+
</dependency>
35+
</dependencies>
36+
37+
<build>
38+
<plugins>
39+
<plugin>
40+
<groupId>org.springframework.boot</groupId>
41+
<artifactId>spring-boot-maven-plugin</artifactId>
42+
</plugin>
43+
</plugins>
44+
</build>
45+
46+
</project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package cc.mrbird.batch;
2+
3+
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
7+
@SpringBootApplication
8+
@EnableBatchProcessing
9+
public class SpringBatchStartApplication {
10+
11+
public static void main(String[] args) {
12+
SpringApplication.run(SpringBatchStartApplication.class, args);
13+
}
14+
15+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package cc.mrbird.batch.decider;
2+
3+
import org.springframework.batch.core.JobExecution;
4+
import org.springframework.batch.core.StepExecution;
5+
import org.springframework.batch.core.job.flow.FlowExecutionStatus;
6+
import org.springframework.batch.core.job.flow.JobExecutionDecider;
7+
import org.springframework.stereotype.Component;
8+
9+
import java.time.DayOfWeek;
10+
import java.time.LocalDate;
11+
12+
/**
13+
* @author MrBird
14+
*/
15+
@Component
16+
public class MyDecider implements JobExecutionDecider {
17+
@Override
18+
public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) {
19+
LocalDate now = LocalDate.now();
20+
DayOfWeek dayOfWeek = now.getDayOfWeek();
21+
22+
if (dayOfWeek == DayOfWeek.SATURDAY || dayOfWeek == DayOfWeek.SUNDAY) {
23+
return new FlowExecutionStatus("weekend");
24+
} else {
25+
return new FlowExecutionStatus("workingDay");
26+
}
27+
}
28+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package cc.mrbird.batch.job;
2+
3+
import cc.mrbird.batch.decider.MyDecider;
4+
import org.springframework.batch.core.Job;
5+
import org.springframework.batch.core.Step;
6+
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
7+
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
8+
import org.springframework.batch.repeat.RepeatStatus;
9+
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.context.annotation.Bean;
11+
import org.springframework.stereotype.Component;
12+
13+
/**
14+
* @author MrBird
15+
*/
16+
@Component
17+
public class DeciderJobDemo {
18+
@Autowired
19+
private JobBuilderFactory jobBuilderFactory;
20+
@Autowired
21+
private StepBuilderFactory stepBuilderFactory;
22+
@Autowired
23+
private MyDecider myDecider;
24+
25+
@Bean
26+
public Job deciderJob() {
27+
return jobBuilderFactory.get("deciderJob")
28+
.start(step1())
29+
.next(myDecider)
30+
.from(myDecider).on("weekend").to(step2())
31+
.from(myDecider).on("workingDay").to(step3())
32+
.from(step3()).on("*").to(step4())
33+
.end()
34+
.build();
35+
}
36+
37+
private Step step1() {
38+
return stepBuilderFactory.get("step1")
39+
.tasklet((stepContribution, chunkContext) -> {
40+
System.out.println("执行步骤一操作。。。");
41+
return RepeatStatus.FINISHED;
42+
}).build();
43+
}
44+
45+
private Step step2() {
46+
return stepBuilderFactory.get("step2")
47+
.tasklet((stepContribution, chunkContext) -> {
48+
System.out.println("执行步骤二操作。。。");
49+
return RepeatStatus.FINISHED;
50+
}).build();
51+
}
52+
53+
private Step step3() {
54+
return stepBuilderFactory.get("step3")
55+
.tasklet((stepContribution, chunkContext) -> {
56+
System.out.println("执行步骤三操作。。。");
57+
return RepeatStatus.FINISHED;
58+
}).build();
59+
}
60+
61+
62+
private Step step4() {
63+
return stepBuilderFactory.get("step4")
64+
.tasklet((stepContribution, chunkContext) -> {
65+
System.out.println("执行步骤四操作。。。");
66+
return RepeatStatus.FINISHED;
67+
}).build();
68+
}
69+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package cc.mrbird.batch.job;
2+
3+
import org.springframework.batch.core.Job;
4+
import org.springframework.batch.core.Step;
5+
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
6+
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
7+
import org.springframework.batch.repeat.RepeatStatus;
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.context.annotation.Bean;
10+
import org.springframework.stereotype.Component;
11+
12+
/**
13+
* @author MrBird
14+
*/
15+
@Component
16+
public class FirstJobDemo {
17+
18+
@Autowired
19+
private JobBuilderFactory jobBuilderFactory;
20+
@Autowired
21+
private StepBuilderFactory stepBuilderFactory;
22+
23+
@Bean
24+
public Job firstJob() {
25+
return jobBuilderFactory.get("firstJob")
26+
.start(step())
27+
.build();
28+
}
29+
30+
private Step step() {
31+
return stepBuilderFactory.get("step")
32+
.tasklet((contribution, chunkContext) -> {
33+
System.out.println("执行步骤....");
34+
return RepeatStatus.FINISHED;
35+
}).build();
36+
}
37+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package cc.mrbird.batch.job;
2+
3+
import org.springframework.batch.core.ExitStatus;
4+
import org.springframework.batch.core.Job;
5+
import org.springframework.batch.core.Step;
6+
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
7+
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
8+
import org.springframework.batch.core.job.builder.FlowBuilder;
9+
import org.springframework.batch.core.job.flow.Flow;
10+
import org.springframework.batch.repeat.RepeatStatus;
11+
import org.springframework.beans.factory.annotation.Autowired;
12+
import org.springframework.context.annotation.Bean;
13+
import org.springframework.stereotype.Component;
14+
15+
/**
16+
* @author MrBird
17+
*/
18+
@Component
19+
public class FlowJobDemo {
20+
21+
@Autowired
22+
private JobBuilderFactory jobBuilderFactory;
23+
@Autowired
24+
private StepBuilderFactory stepBuilderFactory;
25+
26+
@Bean
27+
public Job flowJob() {
28+
return jobBuilderFactory.get("flowJob")
29+
.start(flow())
30+
.next(step3())
31+
.end()
32+
.build();
33+
}
34+
35+
private Step step1() {
36+
return stepBuilderFactory.get("step1")
37+
.tasklet((stepContribution, chunkContext) -> {
38+
System.out.println("执行步骤一操作。。。");
39+
return RepeatStatus.FINISHED;
40+
}).build();
41+
}
42+
43+
private Step step2() {
44+
return stepBuilderFactory.get("step2")
45+
.tasklet((stepContribution, chunkContext) -> {
46+
System.out.println("执行步骤二操作。。。");
47+
return RepeatStatus.FINISHED;
48+
}).build();
49+
}
50+
51+
private Step step3() {
52+
return stepBuilderFactory.get("step3")
53+
.tasklet((stepContribution, chunkContext) -> {
54+
System.out.println("执行步骤三操作。。。");
55+
return RepeatStatus.FINISHED;
56+
}).build();
57+
}
58+
59+
// 创建一个flow对象,包含若干个step
60+
private Flow flow() {
61+
return new FlowBuilder<Flow>("flow")
62+
.start(step1())
63+
.next(step2())
64+
.build();
65+
}
66+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package cc.mrbird.batch.job;
2+
3+
import org.springframework.batch.core.ExitStatus;
4+
import org.springframework.batch.core.Job;
5+
import org.springframework.batch.core.Step;
6+
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
7+
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
8+
import org.springframework.batch.repeat.RepeatStatus;
9+
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.context.annotation.Bean;
11+
import org.springframework.stereotype.Component;
12+
13+
/**
14+
* @author MrBird
15+
*/
16+
@Component
17+
public class MultiStepJobDemo {
18+
19+
@Autowired
20+
private JobBuilderFactory jobBuilderFactory;
21+
@Autowired
22+
private StepBuilderFactory stepBuilderFactory;
23+
24+
@Bean
25+
public Job multiStepJob() {
26+
// return jobBuilderFactory.get("multiStepJob")
27+
// .start(step1())
28+
// .next(step2())
29+
// .next(step3())
30+
// .build();
31+
return jobBuilderFactory.get("multiStepJob2")
32+
.start(step1())
33+
.on(ExitStatus.COMPLETED.getExitCode()).to(step2())
34+
.from(step2())
35+
.on(ExitStatus.COMPLETED.getExitCode()).to(step3())
36+
.from(step3()).end()
37+
.build();
38+
}
39+
40+
private Step step1() {
41+
return stepBuilderFactory.get("step1")
42+
.tasklet((stepContribution, chunkContext) -> {
43+
System.out.println("执行步骤一操作。。。");
44+
return RepeatStatus.FINISHED;
45+
}).build();
46+
}
47+
48+
private Step step2() {
49+
return stepBuilderFactory.get("step2")
50+
.tasklet((stepContribution, chunkContext) -> {
51+
System.out.println("执行步骤二操作。。。");
52+
return RepeatStatus.FINISHED;
53+
}).build();
54+
}
55+
56+
private Step step3() {
57+
return stepBuilderFactory.get("step3")
58+
.tasklet((stepContribution, chunkContext) -> {
59+
System.out.println("执行步骤三操作。。。");
60+
return RepeatStatus.FINISHED;
61+
}).build();
62+
}
63+
}

0 commit comments

Comments
 (0)