├── .gitignore
├── README.md
├── pom.xml
├── springboot-aoplog
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── cn
│ │ │ └── jboost
│ │ │ └── springboot
│ │ │ └── aoplog
│ │ │ ├── SpringbootAoplogApplication.java
│ │ │ └── controller
│ │ │ └── AoplogTestController.java
│ └── resources
│ │ ├── application.yml
│ │ └── logback-spring.xml
│ └── test
│ └── java
│ └── cn
│ └── jboost
│ └── springboot
│ └── aoplog
│ └── SpringbootAoplogApplicationTests.java
├── springboot-async
├── pom.xml
└── src
│ └── main
│ └── java
│ └── cn
│ └── jboost
│ ├── Application.java
│ └── async
│ ├── annotation
│ ├── AnnotationBasedAsyncTest.java
│ ├── AsyncConfig.java
│ └── AsyncService.java
│ └── event
│ ├── EventBasedAsyncTest.java
│ ├── MyEvent.java
│ ├── MyEventHandler.java
│ ├── MyEventHandler2.java
│ └── MyEventPublisher.java
├── springboot-config
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── cn
│ │ │ └── jboost
│ │ │ └── springboot
│ │ │ └── config
│ │ │ ├── MyConfig.java
│ │ │ ├── MyService.java
│ │ │ ├── MyService2.java
│ │ │ └── SpringbootConfigApplication.java
│ └── resources
│ │ ├── application.properties
│ │ └── spring.xml
│ └── test
│ └── java
│ └── cn
│ └── jboost
│ └── springboot
│ └── config
│ └── SpringbootConfigApplicationTests.java
├── springboot-error
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── cn
│ │ │ └── jboost
│ │ │ └── springboot
│ │ │ └── error
│ │ │ ├── FilterConfig.java
│ │ │ ├── SpringbootErrorApplication.java
│ │ │ ├── controller
│ │ │ └── ExceptionTestController.java
│ │ │ └── util
│ │ │ └── ErrorCodeEnum.java
│ └── resources
│ │ └── application.yml
│ └── test
│ └── java
│ └── cn
│ └── jboost
│ └── springboot
│ └── error
│ └── SpringbootErrorApplicationTests.java
├── springboot-file
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── cn
│ │ └── jboost
│ │ └── springboot
│ │ └── file
│ │ ├── Application.java
│ │ ├── FileController.java
│ │ └── FileUtil.java
│ └── resources
│ └── application.yaml
├── springboot-firstapp
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── cn
│ │ │ └── jboost
│ │ │ └── springboot
│ │ │ └── firstapp
│ │ │ ├── HelloController.java
│ │ │ └── SpringbootFirstappApplication.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── cn
│ └── jboost
│ └── springboot
│ └── firstapp
│ └── SpringbootFirstappApplicationTests.java
├── springboot-java
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── cn
│ │ │ └── jboost
│ │ │ └── springboot
│ │ │ └── java
│ │ │ ├── DateTimeBean.java
│ │ │ ├── LocalDateTimeController.java
│ │ │ ├── LocalDateTimeFormatConfig.java
│ │ │ └── SpringbootJavaApplication.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── cn
│ └── jboost
│ └── springboot
│ └── java
│ └── SpringbootJavaApplicationTests.java
├── springboot-limiter
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── cn
│ │ └── jboost
│ │ └── springboot
│ │ └── limiter
│ │ ├── LimiterApplication.java
│ │ └── LimiterController.java
│ └── resources
│ └── application.yaml
├── springboot-mybatisplus
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── cn
│ │ └── jboost
│ │ └── springboot
│ │ └── mybatisplus
│ │ ├── App.java
│ │ ├── LocalDateTimeFormatConfig.java
│ │ ├── controller
│ │ ├── UserController.java
│ │ └── criteria
│ │ │ └── UserQueryCriteria.java
│ │ ├── entity
│ │ └── User.java
│ │ ├── mapper
│ │ └── UserMapper.java
│ │ └── service
│ │ └── UserService.java
│ └── resources
│ ├── application.yml
│ └── db
│ ├── data-h2.sql
│ └── schema-h2.sql
├── springboot-properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── cn
│ │ │ └── jboost
│ │ │ └── springboot
│ │ │ └── properties
│ │ │ ├── MyConfigProperties.java
│ │ │ ├── MyPropertiesUtil.java
│ │ │ └── SpringbootPropertiesApplication.java
│ └── resources
│ │ ├── application-dev.properties
│ │ ├── application-dev.yml
│ │ ├── application.properties
│ │ ├── application.yml
│ │ ├── applicationContext.xml
│ │ └── my.properties
│ └── test
│ └── java
│ └── cn
│ └── jboost
│ └── springboot
│ └── properties
│ ├── SpringbootPropertiesApplicationTests.java
│ ├── SpringbootPropertiesHandleTest.java
│ └── TraditionalPropertiesHandleTest.java
├── springboot-redis-cluster
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── cn
│ │ │ └── jboost
│ │ │ └── springboot
│ │ │ └── redis
│ │ │ └── cluster
│ │ │ ├── RedisClusterApplication.java
│ │ │ ├── config
│ │ │ └── RedisConfig.java
│ │ │ ├── controller
│ │ │ └── UserController.java
│ │ │ ├── entity
│ │ │ └── User.java
│ │ │ └── service
│ │ │ ├── RedisService.java
│ │ │ └── UserService.java
│ └── resources
│ │ └── application.yml
│ └── test
│ └── java
│ └── cn
│ └── jboost
│ └── springboot
│ └── redis
│ └── cluster
│ └── test
│ └── RedisTest.java
├── springboot-redis-sentinel
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── cn
│ │ │ └── jboost
│ │ │ └── springboot
│ │ │ └── redis
│ │ │ └── sentinel
│ │ │ ├── RedisSentinelApplication.java
│ │ │ ├── config
│ │ │ └── RedisConfig.java
│ │ │ ├── controller
│ │ │ └── UserController.java
│ │ │ ├── entity
│ │ │ └── User.java
│ │ │ └── service
│ │ │ ├── RedisService.java
│ │ │ └── UserService.java
│ └── resources
│ │ └── application.yml
│ └── test
│ └── java
│ └── cn
│ └── jboost
│ └── springboot
│ └── redis
│ └── sentinel
│ └── test
│ └── RedisTest.java
├── springboot-redis
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── cn
│ │ │ └── jboost
│ │ │ └── springboot
│ │ │ └── redis
│ │ │ ├── Application.java
│ │ │ ├── RedisKeyExpirationListener.java
│ │ │ └── RedisListenerConfig.java
│ └── resources
│ │ └── application.yaml
│ └── test
│ └── java
│ └── cn
│ └── jboost
│ └── springboot
│ └── redis
│ └── test
│ └── RedisTest.java
├── springboot-security
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── cn
│ │ └── jboost
│ │ └── springboot
│ │ └── security
│ │ ├── Application.java
│ │ ├── HelloController.java
│ │ ├── JboostAuthenticationFilter.java
│ │ ├── SecurityConfig.java
│ │ ├── phone
│ │ ├── PhoneAuthenticationProvider.java
│ │ ├── PhoneAuthenticationToken.java
│ │ └── PhoneUserDetailsService.java
│ │ ├── username
│ │ ├── CompositeUserDetailsChecker.java
│ │ ├── RetryLimitAfterPasswordFailedChecker.java
│ │ ├── UsernameAuthenticationProvider.java
│ │ ├── UsernameAuthenticationToken.java
│ │ └── UsernameUserDetailsService.java
│ │ └── util
│ │ ├── LoginParam.java
│ │ ├── LoginType.java
│ │ └── UserType.java
│ └── resources
│ └── application.yaml
├── springboot-simpleauth
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── cn
│ │ └── jboost
│ │ └── springboot
│ │ └── simpleauth
│ │ ├── SimpleAuthApplication.java
│ │ ├── auth
│ │ ├── AuthInterceptor.java
│ │ ├── AuthUtil.java
│ │ ├── JwtConstant.java
│ │ ├── RedisTokenManager.java
│ │ ├── SkipAuth.java
│ │ └── TokenModel.java
│ │ ├── config
│ │ └── WebConfiguration.java
│ │ ├── controller
│ │ ├── TestContoller.java
│ │ └── UserController.java
│ │ └── util
│ │ ├── ApiResponse.java
│ │ └── WebUtil.java
│ └── resources
│ └── application.yml
├── springboot-starter
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── cn
│ │ └── jboost
│ │ └── springboot
│ │ └── starter
│ │ ├── MyAutoConfig.java
│ │ ├── MyProperties.java
│ │ └── MyService.java
│ └── resources
│ └── META-INF
│ └── spring.factories
├── springboot-swagger
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── cn
│ │ │ └── jboost
│ │ │ └── springboot
│ │ │ └── swagger
│ │ │ ├── SpringbootSwaggerApplication.java
│ │ │ └── SwaggerController.java
│ └── resources
│ │ └── application.yml
│ └── test
│ └── java
│ └── cn
│ └── jboost
│ └── springboot
│ └── swagger
│ └── SpringbootSwaggerApplicationTests.java
├── springboot-tkmapper
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── cn
│ │ │ └── jboost
│ │ │ └── springboot
│ │ │ └── tkmapper
│ │ │ ├── SpringbootTkmapperApplication.java
│ │ │ ├── controller
│ │ │ └── UserController.java
│ │ │ ├── domain
│ │ │ └── User.java
│ │ │ ├── mapper
│ │ │ └── UserMapper.java
│ │ │ └── service
│ │ │ └── UserService.java
│ └── resources
│ │ ├── application.yml
│ │ └── schema.sql
│ └── test
│ └── java
│ └── cn
│ └── jboost
│ └── springboot
│ └── tkmapper
│ └── SpringbootTkmapperApplicationTests.java
└── springboot-usingstarter
├── pom.xml
└── src
├── main
├── java
│ └── cn
│ │ └── jboost
│ │ └── springboot
│ │ └── usingstarter
│ │ └── SpringbootUsingstarterApplication.java
└── resources
│ └── application.properties
└── test
└── java
└── cn
└── jboost
└── springboot
└── usingstarter
└── SpringbootUsingstarterApplicationTests.java
/.gitignore:
--------------------------------------------------------------------------------
1 | HELP.md
2 | /target/
3 | !.mvn/wrapper/maven-wrapper.jar
4 |
5 | ### STS ###
6 | .apt_generated
7 | .classpath
8 | .factorypath
9 | .project
10 | .settings
11 | .springBeans
12 | .sts4-cache
13 |
14 | ### IntelliJ IDEA ###
15 | .idea
16 | *.iws
17 | *.iml
18 | *.ipr
19 |
20 | ### NetBeans ###
21 | /nbproject/private/
22 | /nbbuild/
23 | /dist/
24 | /nbdist/
25 | /.nb-gradle/
26 | /build/
27 |
28 | ### VS Code ###
29 | .vscode/
30 |
31 | /*/.mvn
32 | /*/target
33 | /*/HELP.md
34 | /*/mvnw
35 | /*/mvnw.cmd
36 |
37 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### Spring Boot 相关Demo,基于2.1.5 GA版
2 |
3 | ### 相关技术分享网址: http://blog.jboost.cn
4 |
5 | ### 欢迎关注公众号,及时获取最新分享
6 |
7 |
8 | 
9 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.5.RELEASE
9 |
10 |
11 |
12 | 4.0.0
13 |
14 | com.jboost.springboot
15 | springboot-demos
16 | pom
17 | 1.0-SNAPSHOT
18 |
19 | springboot-simpleauth
20 | springboot-mybatisplus
21 | springboot-redis-sentinel
22 | springboot-redis-cluster
23 | springboot-limiter
24 | springboot-security
25 | springboot-file
26 | springboot-redis
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/springboot-aoplog/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.5.RELEASE
9 |
10 |
11 | cn.jboost.springboot
12 | springboot-aoplog
13 | 0.0.1-SNAPSHOT
14 | springboot-aoplog
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-test
25 | test
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-web
31 |
32 |
33 |
34 |
35 | cn.jboost.springboot
36 | aoplog-spring-boot-starter
37 | 1.2-SNAPSHOT
38 |
39 |
40 |
41 | org.springframework.boot
42 | spring-boot-starter-actuator
43 |
44 |
45 |
46 |
47 | ${project.artifactId}
48 |
49 |
50 | org.springframework.boot
51 | spring-boot-maven-plugin
52 |
53 |
54 |
55 | repackage
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/springboot-aoplog/src/main/java/cn/jboost/springboot/aoplog/SpringbootAoplogApplication.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.aoplog;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SpringbootAoplogApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(SpringbootAoplogApplication.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/springboot-aoplog/src/main/java/cn/jboost/springboot/aoplog/controller/AoplogTestController.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.aoplog.controller;
2 |
3 | import cn.jboost.springboot.logging.annotation.LogInfo;
4 | import org.springframework.web.bind.annotation.GetMapping;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RequestParam;
7 | import org.springframework.web.bind.annotation.RestController;
8 |
9 | /***
10 | *
11 | * @Author ronwxy
12 | * @Date 2019/6/27 13:51
13 | */
14 | @RestController
15 | @RequestMapping("test")
16 | @LogInfo
17 | public class AoplogTestController {
18 |
19 | @GetMapping
20 | public String test(@RequestParam String user){
21 | return "Hi " + user;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/springboot-aoplog/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8080
3 |
4 | spring:
5 | application:
6 | name: aoplog-test
7 |
8 | logger:
9 | path: D:\logs #默认当前项目路径下的logs目录
10 | level: info # 默认info
11 | apiPackage: cn.jboost.springboot.aoplog.controller #必须配置, api接口类所在包
12 | rootPackage: cn.jboost.springboot #必须配置,项目根包,记录该包内各类通过slf4j输出的日志
13 |
--------------------------------------------------------------------------------
/springboot-aoplog/src/main/resources/logback-spring.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | [%date{yyyy-MM-dd HH:mm:ss}] [%-5level] [%thread]
14 | [%logger:%line] --%msg%n
15 |
16 |
17 |
18 |
19 |
20 | ${logPath}/elk/interface.log
21 |
22 |
23 |
24 |
25 | {
26 | "project": "${projectName}",
27 | "timestamp": "%date{\"yyyy-MM-dd'T'HH:mm:ss,SSSZ\"}",
28 | "log_level": "%level",
29 | "thread": "%thread",
30 | "class_name": "%X{callingClass}",
31 | "class_method":"%X{callingMethod}",
32 | "line_number": null,
33 | "message": "%message",
34 | "stack_trace": "%exception{5}",
35 | "req_id": "%X{reqId}",
36 | "elapsed_time": "#asLong{%X{elapsedTime}}"
37 | }
38 |
39 |
40 |
41 |
42 |
43 | INFO
44 |
45 |
46 | ${logPath}/bak/interface.%d{yyyy-MM-dd}.log
47 | 30
48 | 1GB
49 |
50 |
51 |
52 |
53 | ${logPath}/elk/error.log
54 |
55 |
56 |
57 |
58 | {
59 | "project": "${projectName}",
60 | "timestamp": "%date{\"yyyy-MM-dd'T'HH:mm:ss,SSSZ\"}",
61 | "log_level": "%level",
62 | "thread": "%thread",
63 | "class_name": "%class",
64 | "line_number": "#asLong{%line}",
65 | "message": "%message",
66 | "stack_trace": "%exception{5}",
67 | "req_id": "%X{reqId}",
68 | "elapsed_time": "#asLong{%X{elapsedTime}}"
69 | }
70 |
71 |
72 |
73 |
74 |
75 | ERROR
76 |
77 |
78 | ${logPath}/bak/error-%d{yyyy-MM-dd}.log
79 |
80 | 30
81 | 1GB
82 |
83 |
84 |
85 |
86 | ${logPath}/elk/warn.log
87 |
88 | WARN
89 | ACCEPT
90 | DENY
91 |
92 |
93 |
94 |
95 |
96 | {
97 | "project": "${projectName}",
98 | "timestamp": "%date{\"yyyy-MM-dd'T'HH:mm:ss,SSSZ\"}",
99 | "log_level": "%level",
100 | "thread": "%thread",
101 | "class_name": "%class",
102 | "line_number": "#asLong{%line}",
103 | "message": "%message",
104 | "stack_trace": "%exception{5}",
105 | "req_id": "%X{reqId}",
106 | "elapsed_time": "#asLong{%X{elapsedTime}}"
107 | }
108 |
109 |
110 |
111 |
112 |
113 | ${logPath}/bak/warn.%d{yyyy-MM-dd}.log
114 | 30
115 | 1GB
116 |
117 |
118 |
119 |
120 |
121 | ${logPath}/elk/info.log
122 |
123 | INFO
124 | ACCEPT
125 | DENY
126 |
127 |
128 |
129 |
130 |
131 | {
132 | "project": "${projectName}",
133 | "timestamp": "%date{\"yyyy-MM-dd'T'HH:mm:ss,SSSZ\"}",
134 | "log_level": "%level",
135 | "thread": "%thread",
136 | "class_name": "%class",
137 | "line_number": "#asLong{%line}",
138 | "message": "%message",
139 | "stack_trace": "%exception{5}",
140 | "req_id": "%X{reqId}",
141 | "elapsed_time": "#asLong{%X{elapsedTime}}"
142 | }
143 |
144 |
145 |
146 |
147 |
148 | ${logPath}/bak/info.%d{yyyy-MM-dd}.log
149 | 30
150 | 1GB
151 |
152 |
153 |
154 |
155 | ${logPath}/elk/debug.log
156 |
157 | DEBUG
158 | ACCEPT
159 | DENY
160 |
161 |
162 |
163 |
164 |
165 | {
166 | "project": "${projectName}",
167 | "timestamp": "%date{\"yyyy-MM-dd'T'HH:mm:ss,SSSZ\"}",
168 | "log_level": "%level",
169 | "thread": "%thread",
170 | "class_name": "%class",
171 | "line_number": "#asLong{%line}",
172 | "message": "%message",
173 | "stack_trace": "%exception{5}",
174 | "req_id": "%X{reqId}",
175 | "elapsed_time": "#asLong{%X{elapsedTime}}"
176 | }
177 |
178 |
179 |
180 |
181 |
182 | ${logPath}/bak/debug.%d{yyyy-MM-dd}.log
183 |
184 | 30
185 | 1GB
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
--------------------------------------------------------------------------------
/springboot-aoplog/src/test/java/cn/jboost/springboot/aoplog/SpringbootAoplogApplicationTests.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.aoplog;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class SpringbootAoplogApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/springboot-async/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.5.RELEASE
9 |
10 |
11 | 4.0.0
12 |
13 | springboot-async
14 |
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-test
23 |
24 |
25 |
--------------------------------------------------------------------------------
/springboot-async/src/main/java/cn/jboost/Application.java:
--------------------------------------------------------------------------------
1 | package cn.jboost;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.scheduling.annotation.EnableAsync;
6 |
7 | /***
8 | *
9 | * @Author ronwxy
10 | * @Date 2019/7/22 17:20
11 | */
12 | @SpringBootApplication
13 | @EnableAsync
14 | public class Application {
15 |
16 | public static void main(String[] args) {
17 | SpringApplication.run(Application.class, args);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/springboot-async/src/main/java/cn/jboost/async/annotation/AnnotationBasedAsyncTest.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.async.annotation;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.boot.test.context.SpringBootTest;
7 | import org.springframework.test.context.junit4.SpringRunner;
8 |
9 | /***
10 | *
11 | * @Author ronwxy
12 | * @Date 2019/7/22 17:09
13 | */
14 | @RunWith(SpringRunner.class)
15 | @SpringBootTest
16 | public class AnnotationBasedAsyncTest {
17 |
18 | @Autowired
19 | private AsyncService asyncService;
20 |
21 | @Test
22 | public void testAsync() throws InterruptedException {
23 | System.out.println("1. running in thread: " + Thread.currentThread().getName());
24 | asyncService.asyncMethod();
25 |
26 | Thread.sleep(3);
27 | }
28 |
29 | @Test
30 | public void testAysncWithException() throws InterruptedException {
31 | System.out.println("1. running in thread: " + Thread.currentThread().getName());
32 | asyncService.asyncMethodWithException();
33 |
34 | Thread.sleep(3);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/springboot-async/src/main/java/cn/jboost/async/annotation/AsyncConfig.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.async.annotation;
2 |
3 | import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
4 | import org.springframework.beans.factory.annotation.Value;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.scheduling.annotation.AsyncConfigurer;
7 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
8 |
9 | import java.lang.reflect.Method;
10 | import java.util.concurrent.Executor;
11 | import java.util.concurrent.ThreadPoolExecutor;
12 |
13 | /***
14 | *
15 | * @Author ronwxy
16 | * @Date 2019/7/22 16:47
17 | */
18 | @Configuration
19 | public class AsyncConfig implements AsyncConfigurer {
20 |
21 |
22 | @Value("${async.corePoolSize:10}")
23 | private int corePoolSize;
24 |
25 | @Value("${async.maxPoolSize:200}")
26 | private int maxPoolSize;
27 |
28 | @Value("${async.queueCapacity:2000}")
29 | private int queueCapacity;
30 |
31 | @Value("${async.keepAlive:5}")
32 | private int keepAlive;
33 |
34 | public Executor getAsyncExecutor() {
35 | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
36 | executor.setCorePoolSize(corePoolSize);
37 | executor.setMaxPoolSize(maxPoolSize);
38 | executor.setQueueCapacity(queueCapacity);
39 | executor.setKeepAliveSeconds(keepAlive);
40 | executor.setThreadNamePrefix("async-");
41 | executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
42 | executor.setDaemon(false); //以用户线程模式运行
43 | executor.initialize();
44 | return executor;
45 | }
46 |
47 | public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
48 | return new MyAsyncUncaughtExceptionHandler();
49 | }
50 |
51 | public static class MyAsyncUncaughtExceptionHandler implements AsyncUncaughtExceptionHandler {
52 |
53 | public void handleUncaughtException(Throwable throwable, Method method, Object... objects) {
54 | System.out.println("catch exception when invoke " + method.getName());
55 | throwable.printStackTrace();
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/springboot-async/src/main/java/cn/jboost/async/annotation/AsyncService.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.async.annotation;
2 |
3 | import org.springframework.scheduling.annotation.Async;
4 | import org.springframework.stereotype.Service;
5 |
6 | /***
7 | *
8 | * @Author ronwxy
9 | * @Date 2019/7/22 17:00
10 | */
11 | @Service
12 | public class AsyncService {
13 |
14 | @Async
15 | public void asyncMethod(){
16 | System.out.println("2. running in thread: " + Thread.currentThread().getName());
17 | }
18 |
19 | @Async
20 | public void asyncMethodWithException() {
21 | throw new RuntimeException("exception in async method");
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/springboot-async/src/main/java/cn/jboost/async/event/EventBasedAsyncTest.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.async.event;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.boot.test.context.SpringBootTest;
7 | import org.springframework.test.context.junit4.SpringRunner;
8 |
9 | /***
10 | *
11 | * @Author ronwxy
12 | * @Date 2019/7/22 17:40
13 | */
14 | @RunWith(SpringRunner.class)
15 | @SpringBootTest
16 | public class EventBasedAsyncTest {
17 |
18 | @Autowired
19 | private MyEventPublisher myEventPublisher;
20 |
21 | @Test
22 | public void testAsync() throws InterruptedException {
23 | System.out.println("1. running in thread: " + Thread.currentThread().getName());
24 | myEventPublisher.publishEvent(new MyEvent(this,"testing event based async"));
25 | Thread.sleep(3);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/springboot-async/src/main/java/cn/jboost/async/event/MyEvent.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.async.event;
2 |
3 | import org.springframework.context.ApplicationEvent;
4 |
5 | /***
6 | * 事件类
7 | * @Author ronwxy
8 | * @Date 2019/7/22 17:28
9 | */
10 | public class MyEvent extends ApplicationEvent {
11 |
12 | private String arg;
13 |
14 | public MyEvent(Object source, String arg) {
15 | super(source);
16 | this.arg = arg;
17 | }
18 |
19 | public String getArg() {
20 | return arg;
21 | }
22 |
23 | public void setArg(String arg) {
24 | this.arg = arg;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/springboot-async/src/main/java/cn/jboost/async/event/MyEventHandler.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.async.event;
2 |
3 | import org.springframework.context.ApplicationListener;
4 | import org.springframework.scheduling.annotation.Async;
5 | import org.springframework.stereotype.Component;
6 |
7 | /***
8 | * 事件处理类,默认是同步执行的,需要加 @Async 注解
9 | * @Author ronwxy
10 | * @Date 2019/7/22 17:30
11 | */
12 | @Component
13 | @Async
14 | public class MyEventHandler implements ApplicationListener {
15 |
16 | public void onApplicationEvent(MyEvent event) {
17 | System.out.println("2. running in thread: " + Thread.currentThread().getName());
18 | System.out.println("2. arg value: " + event.getArg());
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/springboot-async/src/main/java/cn/jboost/async/event/MyEventHandler2.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.async.event;
2 |
3 | import org.springframework.context.event.EventListener;
4 | import org.springframework.scheduling.annotation.Async;
5 | import org.springframework.stereotype.Component;
6 |
7 | /***
8 | * 事件处理类,基于 @EventListener,默认是同步执行的,需要加 @Async 注解
9 | * @Author ronwxy
10 | * @Date 2019/7/22 17:56
11 | */
12 | @Component
13 | public class MyEventHandler2 {
14 |
15 | @EventListener
16 | @Async
17 | public void handle(MyEvent event){
18 | System.out.println("3. running in thread: " + Thread.currentThread().getName());
19 | System.out.println("3. arg value: " + event.getArg());
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/springboot-async/src/main/java/cn/jboost/async/event/MyEventPublisher.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.async.event;
2 |
3 | import org.springframework.context.ApplicationEvent;
4 | import org.springframework.context.ApplicationEventPublisher;
5 | import org.springframework.context.ApplicationEventPublisherAware;
6 | import org.springframework.stereotype.Component;
7 |
8 | /***
9 | * 事件发布类
10 | * @Author ronwxy
11 | * @Date 2019/7/22 17:37
12 | */
13 | @Component
14 | public class MyEventPublisher implements ApplicationEventPublisherAware {
15 |
16 | protected ApplicationEventPublisher applicationEventPublisher;
17 |
18 | public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
19 | this.applicationEventPublisher = applicationEventPublisher;
20 | }
21 |
22 | public void publishEvent(ApplicationEvent event){
23 | this.applicationEventPublisher.publishEvent(event);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/springboot-config/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.5.RELEASE
9 |
10 |
11 | cn.jboost.springboot
12 | springboot-config
13 | 1.0.0-SNAPSHOT
14 | springboot-config
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-web
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-test
30 | test
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-actuator
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 | org.springframework.boot
44 | spring-boot-maven-plugin
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/springboot-config/src/main/java/cn/jboost/springboot/config/MyConfig.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.config;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.context.annotation.ImportResource;
6 |
7 | /***
8 | * @Desc Java配置类
9 | * @Author ronwxy
10 | * @Date 2019/6/11 16:04
11 | */
12 | @Configuration
13 | @ImportResource("spring.xml") //引入基于xml的配置
14 | public class MyConfig {
15 |
16 | @Bean
17 | public MyService myService(){
18 | return new MyService();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/springboot-config/src/main/java/cn/jboost/springboot/config/MyService.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.config;
2 |
3 | /***
4 | * @Desc
5 | * @Author ronwxy
6 | * @Date 2019/6/11 16:05
7 | */
8 | public class MyService {
9 |
10 | public String sayHello(String name) {
11 | return "Hi from java-based config, " + name;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/springboot-config/src/main/java/cn/jboost/springboot/config/MyService2.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.config;
2 |
3 | /***
4 | * @Desc
5 | * @Author ronwxy
6 | * @Date 2019/6/11 16:13
7 | */
8 | public class MyService2 {
9 |
10 | public String sayHello(String name) {
11 | return "Hi from xml-based config, " + name;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/springboot-config/src/main/java/cn/jboost/springboot/config/SpringbootConfigApplication.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.config;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 | import org.springframework.web.bind.annotation.RequestParam;
8 | import org.springframework.web.bind.annotation.RestController;
9 |
10 | @SpringBootApplication
11 | @RestController
12 | public class SpringbootConfigApplication {
13 |
14 | public static void main(String[] args) {
15 | SpringApplication.run(SpringbootConfigApplication.class, args);
16 | }
17 |
18 | @Autowired
19 | private MyService myService;
20 |
21 |
22 | @RequestMapping("/hi")
23 | public String sayHello(@RequestParam String name){
24 | return myService.sayHello(name);
25 | }
26 |
27 | @Autowired
28 | private MyService2 myService2;
29 |
30 | @RequestMapping("/hi2")
31 | public String sayHello2(@RequestParam String name){
32 | return myService2.sayHello(name);
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/springboot-config/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | management.endpoints.web.exposure.include= *
2 | management.endpoints.web.exposure.exclude=beans,trace
3 | management.endpoint.health.show-details=ALWAYS
4 |
--------------------------------------------------------------------------------
/springboot-config/src/main/resources/spring.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/springboot-config/src/test/java/cn/jboost/springboot/config/SpringbootConfigApplicationTests.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.config;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class SpringbootConfigApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/springboot-error/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.5.RELEASE
9 |
10 |
11 | cn.jboost.springboot
12 | springboot-error
13 | 0.0.1-SNAPSHOT
14 | springboot-error
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-web
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-test
30 | test
31 |
32 |
33 |
34 | cn.jboost.springboot
35 | error-spring-boot-starter
36 | 1.2-SNAPSHOT
37 |
38 |
39 |
40 |
41 |
42 |
43 | org.springframework.boot
44 | spring-boot-maven-plugin
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/springboot-error/src/main/java/cn/jboost/springboot/error/FilterConfig.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.error;
2 |
3 | import org.springframework.boot.web.servlet.FilterRegistrationBean;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.core.Ordered;
7 |
8 | import javax.servlet.*;
9 | import java.io.IOException;
10 |
11 | /***
12 | *
13 | * @Author ronwxy
14 | * @Date 2019/7/3 13:54
15 | */
16 | @Configuration
17 | public class FilterConfig {
18 |
19 | @Bean
20 | public FilterRegistrationBean exceptionFilter() {
21 | ExceptionFilter exceptionFilter = new ExceptionFilter();
22 | FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
23 | filterRegistrationBean.setFilter(exceptionFilter);
24 | filterRegistrationBean.setOrder(Ordered.HIGHEST_PRECEDENCE);
25 | filterRegistrationBean.addUrlPatterns("/exception/filter");
26 | return filterRegistrationBean;
27 | }
28 |
29 | class ExceptionFilter implements Filter {
30 |
31 | @Override
32 | public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
33 | throw new RuntimeException("过滤器抛出异常");
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/springboot-error/src/main/java/cn/jboost/springboot/error/SpringbootErrorApplication.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.error;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SpringbootErrorApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(SpringbootErrorApplication.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/springboot-error/src/main/java/cn/jboost/springboot/error/controller/ExceptionTestController.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.error.controller;
2 |
3 |
4 | import cn.jboost.springboot.common.exception.ExceptionUtil;
5 | import cn.jboost.springboot.error.util.ErrorCodeEnum;
6 | import com.google.common.collect.Maps;
7 | import org.springframework.web.bind.annotation.GetMapping;
8 | import org.springframework.web.bind.annotation.RequestMapping;
9 | import org.springframework.web.bind.annotation.RestController;
10 |
11 | import java.util.Map;
12 |
13 | /***
14 | *
15 | * @Author ronwxy
16 | * @Date 2019/7/3 13:04
17 | */
18 | @RestController
19 | @RequestMapping("exception")
20 | public class ExceptionTestController {
21 |
22 | /**
23 | * 不catch具体异常,主动抛出一个异常交给统一异常处理
24 | * @param
25 | * @return
26 | */
27 | @GetMapping("client")
28 | public void clientSideException(){
29 | ExceptionUtil.rethrowClientSideException(ErrorCodeEnum.authorizer_notexist.getMsg());
30 | }
31 |
32 | /**
33 | * catch具体异常,然后rethrow交给统一异常处理
34 | * @param
35 | * @return
36 | */
37 | @GetMapping("server")
38 | public void serverSideException(){
39 | try {
40 | throw new RuntimeException("运行时异常");
41 | } catch (Exception ex) {
42 | //这里不需要打日志,会统一在异常处理里记录日志
43 | ExceptionUtil.rethrowServerSideException(ErrorCodeEnum.internal_error.getMsg(), ex);
44 | }
45 | }
46 |
47 | /**
48 | * 正常返回
49 | * @param
50 | * @return
51 | */
52 | @GetMapping("normal")
53 | public Map normal(){
54 | Map result = Maps.newLinkedHashMap();
55 | result.put("name","jboost");
56 | result.put("website","blog.jboost.cn");
57 | result.put("wechat","jboost-ksxy");
58 | return result;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/springboot-error/src/main/java/cn/jboost/springboot/error/util/ErrorCodeEnum.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.error.util;
2 |
3 |
4 |
5 | /***
6 | *
7 | * @Author ronwxy
8 | * @Date 2019/7/3 13:04
9 | */
10 | public enum ErrorCodeEnum {
11 |
12 | qrcode_existed("该公众号下已存在同名二维码"),
13 | authorizer_notexist("公众号不存在"),
14 | internal_error("抱歉,服务出错了,请稍后重试"),
15 | gotoauth_fail("跳转授权页面失败");
16 |
17 | private String msg;
18 |
19 | private ErrorCodeEnum(String msg) {
20 | this.msg = msg;
21 | }
22 |
23 |
24 | public String getMsg() {
25 | return msg;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/springboot-error/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/springboot-error/src/test/java/cn/jboost/springboot/error/SpringbootErrorApplicationTests.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.error;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class SpringbootErrorApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/springboot-file/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.5.RELEASE
9 |
10 |
11 | 4.0.0
12 |
13 | springboot-file
14 |
15 |
16 | 8
17 | 8
18 |
19 |
20 |
21 |
22 | cn.hutool
23 | hutool-all
24 | 5.3.5
25 |
26 |
27 | org.springframework.boot
28 | spring-boot-starter-test
29 | test
30 |
31 |
32 |
33 | org.springframework.boot
34 | spring-boot-starter-web
35 |
36 |
37 |
38 | org.springframework.boot
39 | spring-boot-starter-actuator
40 |
41 |
42 |
43 |
44 | ${project.artifactId}
45 |
46 |
47 | org.springframework.boot
48 | spring-boot-maven-plugin
49 |
50 |
51 |
52 | repackage
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/springboot-file/src/main/java/cn/jboost/springboot/file/Application.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.file;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | /**
7 | * @Author ronwxy
8 | * @Date 2021/1/27 15:44
9 | * @Version 1.0
10 | */
11 | @SpringBootApplication
12 | public class Application {
13 |
14 | public static void main(String[] args) {
15 | SpringApplication.run(Application.class, args);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/springboot-file/src/main/java/cn/jboost/springboot/file/FileController.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.file;
2 |
3 | import org.springframework.web.bind.annotation.*;
4 | import org.springframework.web.multipart.MultipartFile;
5 |
6 | import javax.servlet.http.HttpServletRequest;
7 | import javax.servlet.http.HttpServletResponse;
8 | import java.io.*;
9 | import java.util.HashMap;
10 | import java.util.Map;
11 |
12 | /**
13 | * @Author ronwxy
14 | * @Date 2021/1/27 15:33
15 | * @Version 1.0
16 | */
17 | @RestController
18 | @RequestMapping("file")
19 | public class FileController {
20 |
21 | @PostMapping(value = "upload")
22 | public Map upload(@RequestParam MultipartFile file) throws IOException {
23 | String filePath = FileUtil.fileSave("D:\\upload\\", "file", file);
24 | Map map = new HashMap<>();
25 | map.put("filePath",filePath);
26 | return map;
27 | }
28 |
29 | @CrossOrigin
30 | @GetMapping("download")
31 | public void download(@RequestParam("path") String path, HttpServletRequest req, HttpServletResponse res) {
32 | String absolutPath = "D:\\upload\\"+ path;
33 | // 重要,需要设置此值,否则下载后打开文件会提示文件需要修复
34 | File file = new File(absolutPath);
35 | if (file.exists()) {
36 | byte[] buffer = new byte[1024];
37 | OutputStream os;
38 | try (FileInputStream fis= new FileInputStream(file);
39 | BufferedInputStream bis = new BufferedInputStream(fis)) {
40 | os = res.getOutputStream();
41 | int i = bis.read(buffer);
42 | while (i != -1){
43 | os.write(buffer,0,i);
44 | i = bis.read(buffer);
45 | }
46 | } catch (Exception e) {
47 | e.printStackTrace();
48 | }
49 | }
50 |
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/springboot-file/src/main/java/cn/jboost/springboot/file/FileUtil.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.file;
2 |
3 |
4 | import cn.hutool.core.util.IdUtil;
5 | import cn.hutool.core.util.StrUtil;
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 | import org.springframework.util.FileCopyUtils;
9 | import org.springframework.util.ResourceUtils;
10 | import org.springframework.web.multipart.MultipartFile;
11 |
12 | import java.io.File;
13 | import java.io.FileNotFoundException;
14 | import java.io.IOException;
15 | import java.text.DecimalFormat;
16 |
17 | public class FileUtil extends cn.hutool.core.io.FileUtil {
18 | private static final Logger log = LoggerFactory.getLogger(FileUtil.class);
19 | private static final int GB = 1073741824;
20 | private static final int MB = 1048576;
21 | private static final int KB = 1024;
22 | private static final DecimalFormat DF = new DecimalFormat("0.00");
23 |
24 | public FileUtil() {
25 | }
26 |
27 | public static File toFile(MultipartFile multipartFile) {
28 | String fileName = multipartFile.getOriginalFilename();
29 | String prefix = "." + getExtensionName(fileName);
30 | File file = null;
31 |
32 | try {
33 | file = File.createTempFile(IdUtil.simpleUUID(), prefix);
34 | multipartFile.transferTo(file);
35 | } catch (IOException var5) {
36 | log.error("fail to transfer multipartFile[{}] to oss", fileName, var5);
37 | }
38 |
39 | return file;
40 | }
41 |
42 | public static void deleteFile(File... files) {
43 | File[] var1 = files;
44 | int var2 = files.length;
45 |
46 | for (int var3 = 0; var3 < var2; ++var3) {
47 | File file = var1[var3];
48 | if (file.exists()) {
49 | file.delete();
50 | }
51 | }
52 |
53 | }
54 |
55 | public static String getExtensionName(String filename) {
56 | if (filename != null && filename.length() > 0) {
57 | int dot = filename.lastIndexOf(46);
58 | if (dot > -1 && dot < filename.length() - 1) {
59 | return filename.substring(dot + 1);
60 | }
61 | }
62 |
63 | return filename;
64 | }
65 |
66 | public static String getFileNameNoEx(String filename) {
67 | if (filename != null && filename.length() > 0) {
68 | int dot = filename.lastIndexOf(46);
69 | if (dot > -1 && dot < filename.length()) {
70 | return filename.substring(0, dot);
71 | }
72 | }
73 |
74 | return filename;
75 | }
76 |
77 | public static String getSize(int size) {
78 | String resultSize = "";
79 | if (size / 1073741824 >= 1) {
80 | resultSize = DF.format((double) ((float) size / 1.07374182E9F)) + "GB ";
81 | } else if (size / 1048576 >= 1) {
82 | resultSize = DF.format((double) ((float) size / 1048576.0F)) + "MB ";
83 | } else if (size / 1024 >= 1) {
84 | resultSize = DF.format((double) ((float) size / 1024.0F)) + "KB ";
85 | } else {
86 | resultSize = size + "B ";
87 | }
88 |
89 | return resultSize;
90 | }
91 |
92 | /**
93 | * 获取项目根路径
94 | *
95 | * @return
96 | */
97 | public static String getResourceBasePath() {
98 | // 获取跟目录
99 | File path = null;
100 | try {
101 | path = new File(ResourceUtils.getURL("classpath:").getPath());
102 | } catch (FileNotFoundException e) {
103 | // nothing to do
104 | }
105 | if (path == null || !path.exists()) {
106 | path = new File("");
107 | }
108 | String pathStr = path.getAbsolutePath();
109 | // 如果是在eclipse中运行,则和target同级目录,如果是jar部署到服务器,则默认和jar包同级
110 | pathStr = pathStr.replace("\\target\\classes", "");
111 | return pathStr;
112 | }
113 |
114 | /**
115 | * 保证拷贝的文件的目录一定要存在
116 | *
117 | * @param filePath
118 | * 文件路径
119 | */
120 | public static void ensureDirectory(String filePath) {
121 | if (StrUtil.isBlank(filePath)) {
122 | return;
123 | }
124 | //将符号“\\”和“\”替换成“/”,有时候便于统一的处理路径的分隔符,避免同一个路径出现两个或三种不同的分隔符
125 | filePath = filePath.replace("\\", "/").replace("\\\\", "/");
126 | File file = new File(filePath);
127 | if (!file.exists()) {
128 | file.mkdirs();
129 | }
130 | }
131 |
132 | /**
133 | * 上传文件保存
134 | * @param rootPath
135 | * @param bizPath
136 | * @param mf
137 | * @return
138 | * @throws IOException
139 | */
140 | public static String fileSave(String rootPath, String bizPath, MultipartFile mf) throws IOException {
141 | log.info("--------文件正在保存---------" );
142 | String ctxPath = rootPath;
143 | File file = new File(ctxPath + File.separator + bizPath);
144 | if (!file.exists()) {
145 | file.mkdirs();// 创建文件根目录
146 | }
147 | String orgName = mf.getOriginalFilename();// 获取文件名
148 | String filePrefixName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis();
149 | String fileName = filePrefixName + orgName.substring(orgName.indexOf("."));
150 | String savePath = file.getPath() + File.separator + fileName;
151 | File savefile = new File(savePath);
152 | FileCopyUtils.copy(mf.getBytes(), savefile);
153 | String dbpath = bizPath + File.separator + fileName;
154 | if (dbpath.contains("\\")) {
155 | dbpath = dbpath.replace("\\", "/");
156 | }
157 | log.info("--------文件成功保存至" + dbpath);
158 | return dbpath;
159 | }
160 |
161 | /**
162 | * 删除指定的文件
163 | *
164 | * @param strFileName 指定绝对路径的文件名
165 | * @return 如果删除成功true否则false
166 | */
167 | public static boolean delete(String strFileName) {
168 | File fileDelete = new File(strFileName);
169 | if (!fileDelete.exists() || !fileDelete.isFile()) {
170 | log.info("错误: " + strFileName + "不存在!");
171 | return false;
172 | }
173 | log.info("--------成功删除文件---------" + strFileName);
174 | return fileDelete.delete();
175 | }
176 |
177 | }
178 |
--------------------------------------------------------------------------------
/springboot-file/src/main/resources/application.yaml:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ronwxy/springboot-demos/c79579d3b46f07af477e6c56e2d566a434d05ccf/springboot-file/src/main/resources/application.yaml
--------------------------------------------------------------------------------
/springboot-firstapp/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.5.RELEASE
9 |
10 |
11 | cn.jboost.springboot
12 | springboot-firstapp
13 | 1.0.0-SNAPSHOT
14 | springboot-firstapp
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-web
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-test
30 | test
31 |
32 |
33 |
34 |
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-maven-plugin
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/springboot-firstapp/src/main/java/cn/jboost/springboot/firstapp/HelloController.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.firstapp;
2 |
3 | import org.springframework.web.bind.annotation.GetMapping;
4 | import org.springframework.web.bind.annotation.RequestParam;
5 | import org.springframework.web.bind.annotation.RestController;
6 |
7 | @RestController("/hello")
8 | public class HelloController {
9 |
10 | @GetMapping
11 | public String hello(@RequestParam(name = "name")String name){
12 | return "您好," + name;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/springboot-firstapp/src/main/java/cn/jboost/springboot/firstapp/SpringbootFirstappApplication.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.firstapp;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SpringbootFirstappApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(SpringbootFirstappApplication.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/springboot-firstapp/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/springboot-firstapp/src/test/java/cn/jboost/springboot/firstapp/SpringbootFirstappApplicationTests.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.firstapp;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class SpringbootFirstappApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/springboot-java/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.5.RELEASE
9 |
10 |
11 | cn.jboost.springboot
12 | springboot-java
13 | 1.0.0-SNAPSHOT
14 | springboot-java
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-web
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-test
30 | test
31 |
32 |
33 | org.junit.vintage
34 | junit-vintage-engine
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 | org.springframework.boot
44 | spring-boot-maven-plugin
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/springboot-java/src/main/java/cn/jboost/springboot/java/DateTimeBean.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.java;
2 |
3 | import com.fasterxml.jackson.annotation.JsonFormat;
4 | import org.springframework.format.annotation.DateTimeFormat;
5 |
6 | import java.io.Serializable;
7 | import java.time.LocalDate;
8 | import java.time.LocalDateTime;
9 | import java.time.LocalTime;
10 |
11 | /***
12 | *
13 | * @Author ronwxy
14 | * @Date 2019/11/1 16:59
15 | */
16 |
17 | public class DateTimeBean implements Serializable {
18 |
19 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS")
20 | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS")
21 | private LocalDateTime dateTime;
22 | // @JsonFormat(pattern = "yyyy-MM-dd")
23 | private LocalDate date;
24 | private LocalTime time;
25 |
26 | public LocalDateTime getDateTime() {
27 | return dateTime;
28 | }
29 |
30 | public void setDateTime(LocalDateTime dateTime) {
31 | this.dateTime = dateTime;
32 | }
33 |
34 | public LocalDate getDate() {
35 | return date;
36 | }
37 |
38 | public void setDate(LocalDate date) {
39 | this.date = date;
40 | }
41 |
42 | public LocalTime getTime() {
43 | return time;
44 | }
45 |
46 | public void setTime(LocalTime time) {
47 | this.time = time;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/springboot-java/src/main/java/cn/jboost/springboot/java/LocalDateTimeController.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.java;
2 |
3 | import org.springframework.http.HttpStatus;
4 | import org.springframework.http.ResponseEntity;
5 | import org.springframework.web.bind.annotation.*;
6 |
7 | import java.time.LocalDate;
8 | import java.time.LocalDateTime;
9 | import java.time.LocalTime;
10 |
11 | /***
12 | *
13 | * @Author ronwxy
14 | * @Date 2019/11/1 17:08
15 | */
16 | @RestController
17 | @RequestMapping("local-date-time")
18 | public class LocalDateTimeController {
19 |
20 |
21 | @PostMapping
22 | public ResponseEntity setDateTime(@RequestBody DateTimeBean dateTimeBean){
23 | return new ResponseEntity(dateTimeBean, HttpStatus.OK);
24 | }
25 |
26 | @GetMapping
27 | public ResponseEntity getDateTime(){
28 | DateTimeBean dateTimeBean = new DateTimeBean();
29 | dateTimeBean.setDateTime(LocalDateTime.now());
30 | dateTimeBean.setDate(LocalDate.now());
31 | dateTimeBean.setTime(LocalTime.now());
32 | return new ResponseEntity(dateTimeBean, HttpStatus.OK);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/springboot-java/src/main/java/cn/jboost/springboot/java/LocalDateTimeFormatConfig.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.java;
2 |
3 | import com.fasterxml.jackson.databind.ObjectMapper;
4 | import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
5 | import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
6 | import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
7 | import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
8 | import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
9 | import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
10 | import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
11 | import org.springframework.context.annotation.Bean;
12 | import org.springframework.context.annotation.Configuration;
13 | import org.springframework.context.annotation.Primary;
14 |
15 | import java.time.LocalDate;
16 | import java.time.LocalDateTime;
17 | import java.time.LocalTime;
18 | import java.time.format.DateTimeFormatter;
19 |
20 | /***
21 | *
22 | * @Author ronwxy
23 | * @Date 2019/11/1 16:58
24 | */
25 | @Configuration
26 | public class LocalDateTimeFormatConfig {
27 | private static final String DEFAULT_DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
28 | private static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd";
29 | private static final String DEFAULT_TIME_PATTERN = "HH:mm:ss";
30 |
31 | @Bean
32 | @Primary
33 | public ObjectMapper objectMapper(){
34 | ObjectMapper objectMapper = new ObjectMapper();
35 | JavaTimeModule javaTimeModule = new JavaTimeModule();
36 | javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_PATTERN)));
37 | javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN)));
38 | javaTimeModule.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_PATTERN)));
39 | javaTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_PATTERN)));
40 | javaTimeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN)));
41 | javaTimeModule.addDeserializer(LocalTime.class, new LocalTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_PATTERN)));
42 | objectMapper.registerModule(javaTimeModule);
43 | return objectMapper;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/springboot-java/src/main/java/cn/jboost/springboot/java/SpringbootJavaApplication.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.java;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SpringbootJavaApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(SpringbootJavaApplication.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/springboot-java/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/springboot-java/src/test/java/cn/jboost/springboot/java/SpringbootJavaApplicationTests.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.java;
2 |
3 |
4 | import org.junit.Test;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 |
7 | @SpringBootTest
8 | class SpringbootJavaApplicationTests {
9 |
10 | @Test
11 | void contextLoads() {
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/springboot-limiter/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.3.0.RELEASE
9 |
10 |
11 | 4.0.0
12 |
13 | springboot-limiter
14 |
15 |
16 |
17 | cn.jboost.springboot
18 | limiter-spring-boot-starter
19 | 1.3-SNAPSHOT
20 |
21 |
22 | org.springframework.boot
23 | spring-boot-starter-web
24 |
25 |
26 | org.springframework.boot
27 | spring-boot-starter-data-redis
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/springboot-limiter/src/main/java/cn/jboost/springboot/limiter/LimiterApplication.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.limiter;
2 |
3 |
4 | import cn.jboost.springboot.autoconfig.web.Swagger2AutoConfiguration;
5 | import org.springframework.boot.SpringApplication;
6 | import org.springframework.boot.autoconfigure.SpringBootApplication;
7 |
8 | @SpringBootApplication(exclude = {Swagger2AutoConfiguration.class})
9 | public class LimiterApplication {
10 | public static void main(String[] args) {
11 | SpringApplication.run(LimiterApplication.class, args);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/springboot-limiter/src/main/java/cn/jboost/springboot/limiter/LimiterController.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.limiter;
2 |
3 | import cn.jboost.springboot.autoconfig.limiter.*;
4 | import cn.jboost.springboot.common.exception.ExceptionUtil;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.web.bind.annotation.GetMapping;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 | import org.springframework.web.bind.annotation.RequestParam;
9 | import org.springframework.web.bind.annotation.RestController;
10 |
11 | import java.time.LocalDateTime;
12 | import java.util.concurrent.TimeUnit;
13 |
14 | /**
15 | * @Author ronwxy
16 | * @Date 2020/7/15 17:22
17 | * @Version 1.0
18 | */
19 | @RestController
20 | @RequestMapping("limiter")
21 | public class LimiterController {
22 |
23 | @Autowired
24 | private RedisRateLimiterFactory redisRateLimiterFactory;
25 |
26 | /**
27 | * 注解形式
28 | * @param key
29 | * @return
30 | */
31 | @GetMapping("/count")
32 | @CountLimit(key = "#{key}", limit = 2, period = 10, limitType = LimitType.CUSTOM)
33 | public String testCountLimit(@RequestParam("key") String key){
34 | return "test count limiter...";
35 | }
36 |
37 | /**
38 | * 注解形式
39 | * @param key
40 | * @return
41 | */
42 | @GetMapping("/rate")
43 | @RateLimit(rate = 1.0/5, burst = 5.0, expire = 120, timeout = 1)
44 | public String testRateLimit(@RequestParam("key") String key){
45 | return "test rate limiter...";
46 | }
47 |
48 | /**
49 | * 代码段形式
50 | * @param
51 | * @return
52 | */
53 | @GetMapping("/rate2")
54 | public String testRateLimit(){
55 | RedisRateLimiter limiter = redisRateLimiterFactory.build("LimiterController.testRateLimit", 1.0/30, 30, 120);
56 | if(!limiter.tryAcquire("app.limiter", 0, TimeUnit.SECONDS)) {
57 | System.out.println(LocalDateTime.now());
58 | ExceptionUtil.rethrowClientSideException("您的访问过于频繁,请稍后重试");
59 | }
60 | return "test rate limiter 2...";
61 | }
62 |
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/springboot-limiter/src/main/resources/application.yaml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: limiter-demo
4 | redis:
5 | #数据库索引
6 | database: 0
7 | host: 192.168.40.92
8 | port: 6379
9 | password: Passw1rd
10 | #连接超时时间
11 | timeout: 2000
--------------------------------------------------------------------------------
/springboot-mybatisplus/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | cn.jboost.springboot
7 | spring-boot-parent
8 | 1.2-SNAPSHOT
9 |
10 |
11 | 4.0.0
12 |
13 | springboot-mybatisplus
14 |
15 |
16 |
17 | cn.jboost.springboot
18 | mybatisplus-spring-boot-starter
19 | 1.2-SNAPSHOT
20 |
21 |
22 | com.h2database
23 | h2
24 | runtime
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/springboot-mybatisplus/src/main/java/cn/jboost/springboot/mybatisplus/App.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.mybatisplus;
2 |
3 | import org.mybatis.spring.annotation.MapperScan;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 |
7 | @SpringBootApplication
8 | @MapperScan("cn.jboost.springboot.mybatisplus.mapper")
9 | public class App {
10 |
11 | public static void main(String[] args) {
12 | SpringApplication.run(App.class, args);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/springboot-mybatisplus/src/main/java/cn/jboost/springboot/mybatisplus/LocalDateTimeFormatConfig.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.mybatisplus;
2 |
3 | import com.fasterxml.jackson.databind.ObjectMapper;
4 | import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
5 | import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
6 | import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
7 | import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
8 | import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
9 | import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
10 | import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
11 | import org.springframework.context.annotation.Bean;
12 | import org.springframework.context.annotation.Primary;
13 |
14 | import java.time.LocalDate;
15 | import java.time.LocalDateTime;
16 | import java.time.LocalTime;
17 | import java.time.format.DateTimeFormatter;
18 |
19 | /***
20 | *
21 | * @Author ronwxy
22 | * @Date 2019/11/1 16:58
23 | */
24 | //@Configuration
25 | public class LocalDateTimeFormatConfig {
26 | private static final String DEFAULT_DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
27 | private static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd";
28 | private static final String DEFAULT_TIME_PATTERN = "HH:mm:ss";
29 |
30 | @Bean
31 | @Primary
32 | public ObjectMapper objectMapper(){
33 | ObjectMapper objectMapper = new ObjectMapper();
34 | JavaTimeModule javaTimeModule = new JavaTimeModule();
35 | javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_PATTERN)));
36 | javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN)));
37 | javaTimeModule.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_PATTERN)));
38 | javaTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_PATTERN)));
39 | javaTimeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN)));
40 | javaTimeModule.addDeserializer(LocalTime.class, new LocalTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_PATTERN)));
41 | objectMapper.registerModule(javaTimeModule);
42 | return objectMapper;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/springboot-mybatisplus/src/main/java/cn/jboost/springboot/mybatisplus/controller/UserController.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.mybatisplus.controller;
2 |
3 | import cn.jboost.springboot.mybatisplus.controller.criteria.UserQueryCriteria;
4 | import cn.jboost.springboot.mybatisplus.entity.User;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | @RestController
9 | @RequestMapping("/user")
10 | public class UserController extends BaseController {
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/springboot-mybatisplus/src/main/java/cn/jboost/springboot/mybatisplus/controller/criteria/UserQueryCriteria.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.mybatisplus.controller.criteria;
2 |
3 | import cn.jboost.springboot.common.annotation.Query;
4 | import lombok.Data;
5 |
6 | import java.util.List;
7 |
8 | @Data
9 | public class UserQueryCriteria {
10 |
11 | @Query(type = Query.Type.BETWEEN, propName = "age")
12 | private Integer[] ageRange;
13 |
14 | @Query(type = Query.Type.LIKE)
15 | private String name;
16 |
17 | @Query(type = Query.Type.IN, propName = "id")
18 | private List ids;
19 | }
20 |
--------------------------------------------------------------------------------
/springboot-mybatisplus/src/main/java/cn/jboost/springboot/mybatisplus/entity/User.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.mybatisplus.entity;
2 |
3 | import lombok.Data;
4 |
5 | import java.time.LocalDateTime;
6 |
7 | @Data
8 | public class User {
9 | private Long id;
10 | private String name;
11 | private Integer age;
12 | private String email;
13 | // @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
14 | private LocalDateTime createTime;
15 | private LocalDateTime updateTime;
16 | }
17 |
--------------------------------------------------------------------------------
/springboot-mybatisplus/src/main/java/cn/jboost/springboot/mybatisplus/mapper/UserMapper.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.mybatisplus.mapper;
2 |
3 | import cn.jboost.springboot.mybatisplus.entity.User;
4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 | import org.springframework.stereotype.Repository;
6 |
7 | @Repository
8 | public interface UserMapper extends BaseMapper {
9 | }
10 |
--------------------------------------------------------------------------------
/springboot-mybatisplus/src/main/java/cn/jboost/springboot/mybatisplus/service/UserService.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.mybatisplus.service;
2 |
3 | import cn.jboost.springboot.autoconfig.mybatisplus.service.BaseService;
4 | import cn.jboost.springboot.mybatisplus.entity.User;
5 | import org.springframework.stereotype.Service;
6 |
7 | @Service
8 | public class UserService extends BaseService {
9 | }
10 |
--------------------------------------------------------------------------------
/springboot-mybatisplus/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | # DataSource Config
2 | spring:
3 | datasource:
4 | driver-class-name: org.h2.Driver
5 | schema: classpath:db/schema-h2.sql
6 | data: classpath:db/data-h2.sql
7 | url: jdbc:h2:mem:test
8 | username: root
9 | password: test
10 |
11 | # Logger Config
12 | logging:
13 | level:
14 | com.baomidou.mybatisplus.samples.wrapper: debug
15 |
16 | #logging:
17 | # level:
18 | # root: debug
--------------------------------------------------------------------------------
/springboot-mybatisplus/src/main/resources/db/data-h2.sql:
--------------------------------------------------------------------------------
1 | DELETE FROM user;
2 |
3 | INSERT INTO user (id, name, age, email)
4 | VALUES (1, '张三', 18, 'mail1@jboost.cn'),
5 | (2, '张三丰', 20, 'mail1@jboost.cn'),
6 | (3, '李四', 28, 'mail1@jboost.cn'),
7 | (4, '李四姨', 21, 'mail1@jboost.cn'),
8 | (5, '隔壁王五', 24, 'mail1@jboost.cn');
9 |
10 |
--------------------------------------------------------------------------------
/springboot-mybatisplus/src/main/resources/db/schema-h2.sql:
--------------------------------------------------------------------------------
1 | -- noinspection SqlNoDataSourceInspectionForFile
2 |
3 | DROP TABLE IF EXISTS user;
4 |
5 | CREATE TABLE user
6 | (
7 | id BIGINT (20) NOT NULL COMMENT '主键ID',
8 | name VARCHAR(30) NULL DEFAULT NULL COMMENT '姓名',
9 | age INT (11) NULL DEFAULT NULL COMMENT '年龄',
10 | email VARCHAR(50) NULL DEFAULT NULL COMMENT '邮箱',
11 | create_time datetime NULL DEFAULT NULL COMMENT '创建时间',
12 | update_time datetime NULL DEFAULT NULL COMMENT '更新时间',
13 | PRIMARY KEY (id)
14 | );
--------------------------------------------------------------------------------
/springboot-properties/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.5.RELEASE
9 |
10 |
11 | cn.jboost.springboot
12 | springboot-properties
13 | 1.0.0-SNAPSHOT
14 | springboot-properties
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-web
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-test
30 | test
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-actuator
36 |
37 |
38 |
39 |
40 |
41 |
42 | org.springframework.boot
43 | spring-boot-maven-plugin
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/springboot-properties/src/main/java/cn/jboost/springboot/properties/MyConfigProperties.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.properties;
2 |
3 | import org.springframework.boot.context.properties.ConfigurationProperties;
4 | import org.springframework.stereotype.Component;
5 |
6 | /***
7 | * @Desc
8 | * @Author ronwxy
9 | * @Date 2019/6/10 17:53
10 | */
11 | @Component
12 | @ConfigurationProperties(prefix = "my")
13 | public class MyConfigProperties {
14 | private String name;
15 | private String website;
16 |
17 | public String getName() {
18 | return name;
19 | }
20 |
21 | public void setName(String name) {
22 | this.name = name;
23 | }
24 |
25 | public String getWebsite() {
26 | return website;
27 | }
28 |
29 | public void setWebsite(String website) {
30 | this.website = website;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/springboot-properties/src/main/java/cn/jboost/springboot/properties/MyPropertiesUtil.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.properties;
2 |
3 | import java.util.Properties;
4 |
5 | /***
6 | * @Desc 传统自定义属性读取工具类
7 | * @Author ronwxy
8 | * @Date 2019/6/10 17:37
9 | */
10 | public class MyPropertiesUtil {
11 |
12 | private static Properties properties;
13 |
14 | public static void init(Properties props) {
15 | properties = props;
16 | }
17 |
18 | public static String getValue(String key) {
19 | return properties.getProperty(key);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/springboot-properties/src/main/java/cn/jboost/springboot/properties/SpringbootPropertiesApplication.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.properties;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.context.annotation.ImportResource;
6 |
7 | @SpringBootApplication
8 | @ImportResource("classpath:applicationContext.xml")
9 | public class SpringbootPropertiesApplication {
10 |
11 | public static void main(String[] args) {
12 | SpringApplication.run(SpringbootPropertiesApplication.class, args);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/springboot-properties/src/main/resources/application-dev.properties:
--------------------------------------------------------------------------------
1 | my.name=jboost@properties.dev
2 | my.website=blog.jboost.cn@properties.dev
3 |
--------------------------------------------------------------------------------
/springboot-properties/src/main/resources/application-dev.yml:
--------------------------------------------------------------------------------
1 | my:
2 | name: jboost@yml.dev
3 | website: blog.jboost.cn@yml.dev
--------------------------------------------------------------------------------
/springboot-properties/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | my.name=jboost@properties
2 | my.website=blog.jboost.cn@properties
3 |
4 |
5 | management.endpoints.web.exposure.include= *
6 | management.endpoints.web.exposure.exclude=beans,trace
7 | management.endpoint.health.show-details=ALWAYS
--------------------------------------------------------------------------------
/springboot-properties/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | my:
2 | name: jboost@yml
3 | website: blog.jboost.cn@yml
4 |
5 | spring:
6 | profiles:
7 | active: dev
--------------------------------------------------------------------------------
/springboot-properties/src/main/resources/applicationContext.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/springboot-properties/src/main/resources/my.properties:
--------------------------------------------------------------------------------
1 | my.name=jboost
2 | my.website=blog.jboost.cn
--------------------------------------------------------------------------------
/springboot-properties/src/test/java/cn/jboost/springboot/properties/SpringbootPropertiesApplicationTests.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.properties;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class SpringbootPropertiesApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/springboot-properties/src/test/java/cn/jboost/springboot/properties/SpringbootPropertiesHandleTest.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.properties;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.beans.factory.annotation.Value;
7 | import org.springframework.boot.test.context.SpringBootTest;
8 | import org.springframework.core.env.Environment;
9 | import org.springframework.test.context.junit4.SpringRunner;
10 |
11 | /***
12 | * @Desc Springboot 访问自定义属性
13 | * @Author ronwxy
14 | * @Date 2019/6/10 17:53
15 | */
16 | @RunWith(SpringRunner.class)
17 | @SpringBootTest
18 | public class SpringbootPropertiesHandleTest {
19 |
20 | @Autowired
21 | private MyConfigProperties myConfigProperties;
22 |
23 | @Test
24 | public void testConfigurationProperties(){
25 | System.out.println("test @ConfigurationProperties ==========");
26 | System.out.println(myConfigProperties.getName());
27 | System.out.println(myConfigProperties.getWebsite());
28 | }
29 |
30 | @Value("${my.name}")
31 | private String name;
32 | @Value("${my.website}")
33 | private String website;
34 |
35 | @Test
36 | public void testValue(){
37 | System.out.println("test @Value ==========");
38 | System.out.println(name);
39 | System.out.println(website);
40 | }
41 |
42 | @Autowired
43 | private Environment env;
44 |
45 | @Test
46 | public void testEnvironment(){
47 | System.out.println("test Environment ==========");
48 | System.out.println(env.getProperty("my.name"));
49 | System.out.println(env.getProperty("my.website", "default value"));
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/springboot-properties/src/test/java/cn/jboost/springboot/properties/TraditionalPropertiesHandleTest.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.properties;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | /***
9 | * @Desc 传统自定义属性获取测试
10 | * @Author ronwxy
11 | * @Date 2019/6/10 17:42
12 | */
13 | @RunWith(SpringRunner.class)
14 | @SpringBootTest
15 | public class TraditionalPropertiesHandleTest {
16 |
17 | @Test
18 | public void test(){
19 | System.out.println(MyPropertiesUtil.getValue("my.name"));
20 | System.out.println(MyPropertiesUtil.getValue("my.website"));
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/springboot-redis-cluster/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.5.RELEASE
9 |
10 |
11 | 4.0.0
12 |
13 | springboot-redis-cluster
14 |
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter-test
19 | test
20 |
21 |
22 | org.springframework.boot
23 | spring-boot-starter-web
24 |
25 |
26 | org.springframework.boot
27 | spring-boot-starter-data-redis
28 |
29 |
30 | org.projectlombok
31 | lombok
32 | 1.18.8
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/springboot-redis-cluster/src/main/java/cn/jboost/springboot/redis/cluster/RedisClusterApplication.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.redis.cluster;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class RedisClusterApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(RedisClusterApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/springboot-redis-cluster/src/main/java/cn/jboost/springboot/redis/cluster/config/RedisConfig.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.redis.cluster.config;
2 |
3 | import com.fasterxml.jackson.annotation.JsonAutoDetect;
4 | import com.fasterxml.jackson.annotation.PropertyAccessor;
5 | import com.fasterxml.jackson.databind.ObjectMapper;
6 | import org.springframework.cache.annotation.EnableCaching;
7 | import org.springframework.context.annotation.Bean;
8 | import org.springframework.context.annotation.Configuration;
9 | import org.springframework.data.redis.connection.RedisConnectionFactory;
10 | import org.springframework.data.redis.core.RedisTemplate;
11 | import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
12 | import org.springframework.data.redis.serializer.StringRedisSerializer;
13 |
14 | @Configuration
15 | @EnableCaching
16 | public class RedisConfig {
17 |
18 | @Bean
19 | public RedisTemplate redisTemplate(RedisConnectionFactory factory) {
20 | RedisTemplate template = new RedisTemplate<>();
21 | template.setConnectionFactory(factory);
22 |
23 | // 使用Jackson2JsonRedisSerialize 替换默认的jdkSerializeable序列化
24 | Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
25 | ObjectMapper om = new ObjectMapper();
26 | om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
27 | om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
28 | jackson2JsonRedisSerializer.setObjectMapper(om);
29 |
30 | StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
31 |
32 | // key采用String的序列化方式
33 | template.setKeySerializer(stringRedisSerializer);
34 | // hash的key也采用String的序列化方式
35 | template.setHashKeySerializer(stringRedisSerializer);
36 | // value序列化方式采用jackson
37 | template.setValueSerializer(jackson2JsonRedisSerializer);
38 | // hash的value序列化方式采用jackson
39 | template.setHashValueSerializer(jackson2JsonRedisSerializer);
40 | template.afterPropertiesSet();
41 | return template;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/springboot-redis-cluster/src/main/java/cn/jboost/springboot/redis/cluster/controller/UserController.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.redis.cluster.controller;
2 |
3 |
4 | import cn.jboost.springboot.redis.cluster.entity.User;
5 | import cn.jboost.springboot.redis.cluster.service.UserService;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.web.bind.annotation.*;
8 |
9 | @RestController
10 | @RequestMapping("user")
11 | public class UserController {
12 |
13 | @Autowired
14 | private UserService userService;
15 |
16 | @PostMapping
17 | public User addUser(@RequestBody User user){
18 | return userService.addUser(user);
19 | }
20 |
21 | @PostMapping("/2")
22 | public User addUser2(@RequestBody User user){
23 | return userService.addUser2(user);
24 | }
25 |
26 | @GetMapping
27 | public User queryByUsername(@RequestParam("username") String username) {
28 | return userService.queryByUsername(username);
29 | }
30 |
31 | @DeleteMapping("/{username}")
32 | public void deleteByUsername(@PathVariable("username") String username){
33 | userService.deleteByUsername(username);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/springboot-redis-cluster/src/main/java/cn/jboost/springboot/redis/cluster/entity/User.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.redis.cluster.entity;
2 |
3 | import lombok.Data;
4 |
5 | import java.io.Serializable;
6 |
7 | @Data
8 | public class User implements Serializable {
9 | private String uid;
10 | private String username;
11 | private String name;
12 | private Integer age;
13 | }
14 |
--------------------------------------------------------------------------------
/springboot-redis-cluster/src/main/java/cn/jboost/springboot/redis/cluster/service/RedisService.java:
--------------------------------------------------------------------------------
1 | package cn.jboost.springboot.redis.cluster.service;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.data.redis.core.RedisTemplate;
5 | import org.springframework.stereotype.Component;
6 | import org.springframework.util.CollectionUtils;
7 |
8 | import java.util.List;
9 | import java.util.Map;
10 | import java.util.Set;
11 | import java.util.concurrent.TimeUnit;
12 |
13 | @Component
14 | public class RedisService {
15 |
16 | @Autowired
17 | private RedisTemplate redisTemplate;
18 |
19 | /**
20 | * 指定缓存失效时间
21 | *
22 | * @param key 键
23 | * @param time 时间(秒)
24 | * @return
25 | */
26 | public boolean expire(String key, long time) {
27 | try {
28 | if (time > 0) {
29 | redisTemplate.expire(key, time, TimeUnit.SECONDS);
30 | }
31 | return true;
32 | } catch (Exception e) {
33 | return false;
34 | }
35 | }
36 |
37 | /**
38 | * 根据key获取过期时间
39 | *
40 | * @param key 键 不能为null
41 | * @return 时间(秒) 返回0代表为永久有效
42 | */
43 | public long getExpire(String key) {
44 | return redisTemplate.getExpire(key, TimeUnit.SECONDS);
45 | }
46 |
47 | /**
48 | * 判断key是否存在
49 | *
50 | * @param key 键
51 | * @return true 存在 false不存在
52 | */
53 | public boolean hasKey(String key) {
54 | try {
55 | return redisTemplate.hasKey(key);
56 | } catch (Exception e) {
57 | return false;
58 | }
59 | }
60 |
61 | /**
62 | * 删除缓存
63 | *
64 | * @param key 可以传一个值 或多个
65 | */
66 | @SuppressWarnings("unchecked")
67 | public void del(String... key) {
68 | if (key != null && key.length > 0) {
69 | if (key.length == 1) {
70 | redisTemplate.delete(key[0]);
71 | } else {
72 | redisTemplate.delete(CollectionUtils.arrayToList(key));
73 | }
74 | }
75 | }
76 |
77 | /**
78 | * 普通缓存获取
79 | *
80 | * @param key 键
81 | * @return 值
82 | */
83 | public Object get(String key) {
84 | return key == null ? null : redisTemplate.opsForValue().get(key);
85 | }
86 |
87 | /**
88 | * 普通缓存放入
89 | *
90 | * @param key 键
91 | * @param value 值
92 | * @return true成功 false失败
93 | */
94 | public boolean set(String key, Object value) {
95 | try {
96 | redisTemplate.opsForValue().set(key, value);
97 | return true;
98 | } catch (Exception e) {
99 | return false;
100 | }
101 |
102 | }
103 |
104 | /**
105 | * 普通缓存放入并设置时间
106 | *
107 | * @param key 键
108 | * @param value 值
109 | * @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期
110 | * @return true成功 false 失败
111 | */
112 | public boolean set(String key, Object value, long time) {
113 | try {
114 | if (time > 0) {
115 | redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
116 | } else {
117 | set(key, value);
118 | }
119 | return true;
120 | } catch (Exception e) {
121 | return false;
122 | }
123 | }
124 |
125 | /**
126 | * 递增
127 | *
128 | * @param key 键
129 | * @param delta 要增加几(大于0)
130 | * @return
131 | */
132 | public long incr(String key, long delta) {
133 | if (delta <= 0) {
134 | throw new RuntimeException("递增因子必须大于0");
135 | }
136 | return redisTemplate.opsForValue().increment(key, delta);
137 | }
138 |
139 | /**
140 | * 递减
141 | *
142 | * @param key 键
143 | * @param delta 要减少几(小于0)
144 | * @return
145 | */
146 | public long decr(String key, long delta) {
147 | if (delta <= 0) {
148 | throw new RuntimeException("递减因子必须大于0");
149 | }
150 | return redisTemplate.opsForValue().increment(key, -delta);
151 | }
152 |
153 | /**
154 | * HashGet
155 | *
156 | * @param key 键 不能为null
157 | * @param item 项 不能为null
158 | * @return 值
159 | */
160 | public Object hget(String key, String item) {
161 | return redisTemplate.opsForHash().get(key, item);
162 | }
163 |
164 | /**
165 | * 获取hashKey对应的所有键值
166 | *
167 | * @param key 键
168 | * @return 对应的多个键值
169 | */
170 | public Map