diff --git a/.gitignore b/.gitignore index c0d329d..2d85157 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,9 @@ SpringBootCodeBase.iml /SpringBoot-LTS/target/ /logs/ /springBoot-ShardingJDBC/target/ +/SpringBoot-mybatis-plus/target/ +/SpringBoot-OSS/target/ +/SpringBoot-rocketMQ-producer/ +/SpringBoot-rocketMQ-producer/mq-producer.iml +/SpringBoot-Security/target/ +/SpringBoot-rocketMQ-consumer/target/ \ No newline at end of file diff --git a/SpringBoot-AOP/pom.xml b/SpringBoot-AOP/pom.xml index c30fbf8..6115baa 100644 --- a/SpringBoot-AOP/pom.xml +++ b/SpringBoot-AOP/pom.xml @@ -43,6 +43,14 @@ fastjson 1.2.41 + + + org.hibernate.validator + hibernate-validator + 6.1.2.Final + + + diff --git a/SpringBoot-AOP/src/main/java/com/fancv/ExceptionHandler/GlobalExceptionHandler.java b/SpringBoot-AOP/src/main/java/com/fancv/ExceptionHandler/GlobalExceptionHandler.java index 6e91b28..af1f257 100644 --- a/SpringBoot-AOP/src/main/java/com/fancv/ExceptionHandler/GlobalExceptionHandler.java +++ b/SpringBoot-AOP/src/main/java/com/fancv/ExceptionHandler/GlobalExceptionHandler.java @@ -3,16 +3,22 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.HttpServletRequest; +import javax.validation.ConstraintViolationException; +import javax.validation.ValidationException; @ControllerAdvice public class GlobalExceptionHandler { private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class); + private static String DUPLICATE_KEY_CODE = "1001"; + private static String PARAM_FAIL_CODE = "1002"; + private static String VALIDATION_CODE = "1003"; /** * 处理自定义的业务异常 * @param req @@ -52,5 +58,36 @@ public ResultBody exceptionHandler(HttpServletRequest req, Exception e){ logger.error("未知异常!原因是:",e); return ResultBody.error(CommonEnum.INTERNAL_SERVER_ERROR); } + + + /** + * 方法参数校验 + */ + @ExceptionHandler(MethodArgumentNotValidException.class) + @ResponseBody + public ResultBody handleMethodArgumentNotValidException(MethodArgumentNotValidException e) { + logger.error(e.getMessage(), e); + return ResultBody.error(PARAM_FAIL_CODE, e.getBindingResult().getFieldError().getDefaultMessage()); + } + + /** + * ValidationException + */ + @ExceptionHandler(ValidationException.class) + @ResponseBody + public ResultBody handleValidationException(ValidationException e) { + logger.error(e.getMessage(), e); + return ResultBody.error(VALIDATION_CODE, e.getCause().getMessage()); + } + + /** + * ConstraintViolationException + */ + @ExceptionHandler(ConstraintViolationException.class) + @ResponseBody + public ResultBody handleConstraintViolationException(ConstraintViolationException e) { + logger.error(e.getMessage(), e); + return ResultBody.error(PARAM_FAIL_CODE, e.getMessage()); + } } diff --git a/SpringBoot-AOP/src/main/java/com/fancv/ExceptionHandler/ResultBody.java b/SpringBoot-AOP/src/main/java/com/fancv/ExceptionHandler/ResultBody.java index 874ea20..d220288 100644 --- a/SpringBoot-AOP/src/main/java/com/fancv/ExceptionHandler/ResultBody.java +++ b/SpringBoot-AOP/src/main/java/com/fancv/ExceptionHandler/ResultBody.java @@ -2,7 +2,9 @@ import com.alibaba.fastjson.JSONObject; +import lombok.Data; +@Data public class ResultBody { /** * 响应代码 diff --git a/SpringBoot-AOP/src/main/java/com/fancv/controller/UserListController.java b/SpringBoot-AOP/src/main/java/com/fancv/controller/UserListController.java index 27e142d..9c2de53 100644 --- a/SpringBoot-AOP/src/main/java/com/fancv/controller/UserListController.java +++ b/SpringBoot-AOP/src/main/java/com/fancv/controller/UserListController.java @@ -1,18 +1,22 @@ package com.fancv.controller; +import com.alibaba.fastjson.JSON; +import com.fancv.login.BaseUserDTO; import com.fancv.permission.PermissionAnnotation; import io.swagger.annotations.Api; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.BindingResult; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import javax.validation.Valid; import java.util.ArrayList; import java.util.List; @RestController @RequestMapping("user/") @Api(tags = "1.user") +@Slf4j public class UserListController { @@ -30,4 +34,11 @@ public String userLogin(@RequestParam(defaultValue = "001") String userId) { return "登录成功!"; } + @PostMapping("login_1") + public String login(@RequestBody @Validated BaseUserDTO baseUserDTO) { + + log.info(JSON.toJSONString(baseUserDTO)); + return "OK"; + } + } diff --git a/SpringBoot-AOP/src/main/java/com/fancv/login/BaseUserDTO.java b/SpringBoot-AOP/src/main/java/com/fancv/login/BaseUserDTO.java index 5f8b097..eca5a05 100644 --- a/SpringBoot-AOP/src/main/java/com/fancv/login/BaseUserDTO.java +++ b/SpringBoot-AOP/src/main/java/com/fancv/login/BaseUserDTO.java @@ -2,11 +2,15 @@ import lombok.Data; +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import java.io.Serializable; import java.util.List; @Data -public class BaseUserDTO { +public class BaseUserDTO implements Serializable { + @NotNull(message = "用户姓名不能为空") String userNmae; String userPermission; @@ -15,6 +19,9 @@ public class BaseUserDTO { List permissions; + @Valid + EnterDTO enterDTO; + public void addPeemission(String p) { this.permissions.add(p); } diff --git a/SpringBoot-AOP/src/main/java/com/fancv/login/EnterDTO.java b/SpringBoot-AOP/src/main/java/com/fancv/login/EnterDTO.java new file mode 100644 index 0000000..bb3ca76 --- /dev/null +++ b/SpringBoot-AOP/src/main/java/com/fancv/login/EnterDTO.java @@ -0,0 +1,17 @@ +package com.fancv.login; + +import io.swagger.annotations.ApiModel; +import lombok.Data; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; + + +@ApiModel("enterDTO") +@Data +public class EnterDTO { + + @NotNull(message = "not empty") + @Min(1) + private Long version; +} diff --git a/SpringBoot-AOP/target/classes/com/fancv/ExceptionHandler/GlobalExceptionHandler.class b/SpringBoot-AOP/target/classes/com/fancv/ExceptionHandler/GlobalExceptionHandler.class index ba749be..783254f 100644 Binary files a/SpringBoot-AOP/target/classes/com/fancv/ExceptionHandler/GlobalExceptionHandler.class and b/SpringBoot-AOP/target/classes/com/fancv/ExceptionHandler/GlobalExceptionHandler.class differ diff --git a/SpringBoot-AOP/target/classes/com/fancv/controller/UserListController.class b/SpringBoot-AOP/target/classes/com/fancv/controller/UserListController.class index 0884489..e1454a7 100644 Binary files a/SpringBoot-AOP/target/classes/com/fancv/controller/UserListController.class and b/SpringBoot-AOP/target/classes/com/fancv/controller/UserListController.class differ diff --git a/SpringBoot-AOP/target/classes/com/fancv/login/BaseUserDTO.class b/SpringBoot-AOP/target/classes/com/fancv/login/BaseUserDTO.class index 24cf52f..13a2154 100644 Binary files a/SpringBoot-AOP/target/classes/com/fancv/login/BaseUserDTO.class and b/SpringBoot-AOP/target/classes/com/fancv/login/BaseUserDTO.class differ diff --git a/SpringBoot-Commons/src/main/java/com/fancv/App.java b/SpringBoot-Commons/src/main/java/com/fancv/App.java new file mode 100644 index 0000000..5241cdf --- /dev/null +++ b/SpringBoot-Commons/src/main/java/com/fancv/App.java @@ -0,0 +1,13 @@ +package com.fancv; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + } +} diff --git a/SpringBoot-Commons/src/test/java/com/fancv/AppTest.java b/SpringBoot-Commons/src/test/java/com/fancv/AppTest.java new file mode 100644 index 0000000..84d0c0b --- /dev/null +++ b/SpringBoot-Commons/src/test/java/com/fancv/AppTest.java @@ -0,0 +1,20 @@ +package com.fancv; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +/** + * Unit test for simple App. + */ +public class AppTest +{ + /** + * Rigorous Test :-) + */ + @Test + public void shouldAnswerWithTrue() + { + assertTrue( true ); + } +} diff --git a/SpringBoot-OSS/lib/SpringBoot-Commons-1.0-SNAPSHOT.jar b/SpringBoot-Commons/target/SpringBoot-Commons-1.0-SNAPSHOT.jar similarity index 100% rename from SpringBoot-OSS/lib/SpringBoot-Commons-1.0-SNAPSHOT.jar rename to SpringBoot-Commons/target/SpringBoot-Commons-1.0-SNAPSHOT.jar diff --git a/SpringBoot-Commons/target/classes/com/fancv/App.class b/SpringBoot-Commons/target/classes/com/fancv/App.class new file mode 100644 index 0000000..b4bb0ca Binary files /dev/null and b/SpringBoot-Commons/target/classes/com/fancv/App.class differ diff --git a/SpringBoot-Commons/target/classes/com/ray/sdk/OssUtil/GetTime.class b/SpringBoot-Commons/target/classes/com/ray/sdk/OssUtil/GetTime.class new file mode 100644 index 0000000..b8bbb3f Binary files /dev/null and b/SpringBoot-Commons/target/classes/com/ray/sdk/OssUtil/GetTime.class differ diff --git a/SpringBoot-Commons/target/classes/com/ray/sdk/OssUtil/RayOssUtil.class b/SpringBoot-Commons/target/classes/com/ray/sdk/OssUtil/RayOssUtil.class new file mode 100644 index 0000000..9c836aa Binary files /dev/null and b/SpringBoot-Commons/target/classes/com/ray/sdk/OssUtil/RayOssUtil.class differ diff --git a/SpringBoot-Commons/target/classes/com/ray/sdk/config/ossConfig.class b/SpringBoot-Commons/target/classes/com/ray/sdk/config/ossConfig.class new file mode 100644 index 0000000..f0620a7 Binary files /dev/null and b/SpringBoot-Commons/target/classes/com/ray/sdk/config/ossConfig.class differ diff --git a/SpringBoot-Commons/target/maven-archiver/pom.properties b/SpringBoot-Commons/target/maven-archiver/pom.properties new file mode 100644 index 0000000..701d2ab --- /dev/null +++ b/SpringBoot-Commons/target/maven-archiver/pom.properties @@ -0,0 +1,4 @@ +#Created by Apache Maven 3.3.9 +groupId=com.fancv +artifactId=SpringBoot-Commons +version=1.0-SNAPSHOT diff --git a/SpringBoot-Commons/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/SpringBoot-Commons/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..d616d1e --- /dev/null +++ b/SpringBoot-Commons/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,4 @@ +com\fancv\App.class +com\ray\sdk\config\ossConfig.class +com\ray\sdk\OssUtil\RayOssUtil.class +com\ray\sdk\OssUtil\GetTime.class diff --git a/SpringBoot-Commons/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/SpringBoot-Commons/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..43dcc68 --- /dev/null +++ b/SpringBoot-Commons/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,4 @@ +D:\java\IdeaProjects\SpringBootCodeBase\SpringBoot-Commons\src\main\java\com\fancv\App.java +D:\java\IdeaProjects\SpringBootCodeBase\SpringBoot-Commons\src\main\java\com\ray\sdk\OssUtil\GetTime.java +D:\java\IdeaProjects\SpringBootCodeBase\SpringBoot-Commons\src\main\java\com\ray\sdk\config\ossConfig.java +D:\java\IdeaProjects\SpringBootCodeBase\SpringBoot-Commons\src\main\java\com\ray\sdk\OssUtil\RayOssUtil.java diff --git a/SpringBoot-Commons/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/SpringBoot-Commons/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 0000000..273d1c8 --- /dev/null +++ b/SpringBoot-Commons/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -0,0 +1 @@ +com\fancv\AppTest.class diff --git a/SpringBoot-Commons/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/SpringBoot-Commons/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..db61977 --- /dev/null +++ b/SpringBoot-Commons/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1 @@ +D:\java\IdeaProjects\SpringBootCodeBase\SpringBoot-Commons\src\test\java\com\fancv\AppTest.java diff --git a/SpringBoot-Commons/target/site/css/maven-base.css b/SpringBoot-Commons/target/site/css/maven-base.css new file mode 100644 index 0000000..322efae --- /dev/null +++ b/SpringBoot-Commons/target/site/css/maven-base.css @@ -0,0 +1,168 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +body { + margin: 0px; + padding: 0px; +} +table { + padding:0px; + width: 100%; + margin-left: -2px; + margin-right: -2px; +} +acronym { + cursor: help; + border-bottom: 1px dotted #feb; +} +table.bodyTable th, table.bodyTable td { + padding: 2px 4px 2px 4px; + vertical-align: top; +} +div.clear{ + clear:both; + visibility: hidden; +} +div.clear hr{ + display: none; +} +#bannerLeft, #bannerRight { + font-size: xx-large; + font-weight: bold; +} +#bannerLeft img, #bannerRight img { + margin: 0px; +} +.xleft, #bannerLeft img { + float:left; +} +.xright, #bannerRight { + float:right; +} +#banner { + padding: 0px; +} +#breadcrumbs { + padding: 3px 10px 3px 10px; +} +#leftColumn { + width: 170px; + float:left; + overflow: auto; +} +#bodyColumn { + margin-right: 1.5em; + margin-left: 197px; +} +#legend { + padding: 8px 0 8px 0; +} +#navcolumn { + padding: 8px 4px 0 8px; +} +#navcolumn h5 { + margin: 0; + padding: 0; + font-size: small; +} +#navcolumn ul { + margin: 0; + padding: 0; + font-size: small; +} +#navcolumn li { + list-style-type: none; + background-image: none; + background-repeat: no-repeat; + background-position: 0 0.4em; + padding-left: 16px; + list-style-position: outside; + line-height: 1.2em; + font-size: smaller; +} +#navcolumn li.expanded { + background-image: url(../images/expanded.gif); +} +#navcolumn li.collapsed { + background-image: url(../images/collapsed.gif); +} +#navcolumn li.none { + text-indent: -1em; + margin-left: 1em; +} +#poweredBy { + text-align: center; +} +#navcolumn img { + margin-top: 10px; + margin-bottom: 3px; +} +#poweredBy img { + display:block; + margin: 20px 0 20px 17px; +} +#search img { + margin: 0px; + display: block; +} +#search #q, #search #btnG { + border: 1px solid #999; + margin-bottom:10px; +} +#search form { + margin: 0px; +} +#lastPublished { + font-size: x-small; +} +.navSection { + margin-bottom: 2px; + padding: 8px; +} +.navSectionHead { + font-weight: bold; + font-size: x-small; +} +.section { + padding: 4px; +} +#footer { + padding: 3px 10px 3px 10px; + font-size: x-small; +} +#breadcrumbs { + font-size: x-small; + margin: 0pt; +} +.source { + padding: 12px; + margin: 1em 7px 1em 7px; +} +.source pre { + margin: 0px; + padding: 0px; +} +#navcolumn img.imageLink, .imageLink { + padding-left: 0px; + padding-bottom: 0px; + padding-top: 0px; + padding-right: 2px; + border: 0px; + margin: 0px; +} diff --git a/SpringBoot-Commons/target/site/css/maven-theme.css b/SpringBoot-Commons/target/site/css/maven-theme.css new file mode 100644 index 0000000..d3407e8 --- /dev/null +++ b/SpringBoot-Commons/target/site/css/maven-theme.css @@ -0,0 +1,161 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +body { + padding: 0px 0px 10px 0px; +} +body, td, select, input, li{ + font-family: Verdana, Helvetica, Arial, sans-serif; + font-size: 13px; +} +code{ + font-family: Courier, monospace; + font-size: 13px; +} +a { + text-decoration: none; +} +a:link { + color:#36a; +} +a:visited { + color:#47a; +} +a:active, a:hover { + color:#69c; +} +#legend li.externalLink { + background: url(../images/external.png) left top no-repeat; + padding-left: 18px; +} +a.externalLink, a.externalLink:link, a.externalLink:visited, a.externalLink:active, a.externalLink:hover { + background: url(../images/external.png) right center no-repeat; + padding-right: 18px; +} +#legend li.newWindow { + background: url(../images/newwindow.png) left top no-repeat; + padding-left: 18px; +} +a.newWindow, a.newWindow:link, a.newWindow:visited, a.newWindow:active, a.newWindow:hover { + background: url(../images/newwindow.png) right center no-repeat; + padding-right: 18px; +} +h2 { + padding: 4px 4px 4px 6px; + border: 1px solid #999; + color: #900; + background-color: #ddd; + font-weight:900; + font-size: x-large; +} +h3 { + padding: 4px 4px 4px 6px; + border: 1px solid #aaa; + color: #900; + background-color: #eee; + font-weight: normal; + font-size: large; +} +h4 { + padding: 4px 4px 4px 6px; + border: 1px solid #bbb; + color: #900; + background-color: #fff; + font-weight: normal; + font-size: large; +} +h5 { + padding: 4px 4px 4px 6px; + color: #900; + font-size: medium; +} +p { + line-height: 1.3em; + font-size: small; +} +#breadcrumbs { + border-top: 1px solid #aaa; + border-bottom: 1px solid #aaa; + background-color: #ccc; +} +#leftColumn { + margin: 10px 0 0 5px; + border: 1px solid #999; + background-color: #eee; + padding-bottom: 3px; /* IE-9 scrollbar-fix */ +} +#navcolumn h5 { + font-size: smaller; + border-bottom: 1px solid #aaaaaa; + padding-top: 2px; + color: #000; +} + +table.bodyTable th { + color: white; + background-color: #bbb; + text-align: left; + font-weight: bold; +} + +table.bodyTable th, table.bodyTable td { + font-size: 1em; +} + +table.bodyTable tr.a { + background-color: #ddd; +} + +table.bodyTable tr.b { + background-color: #eee; +} + +.source { + border: 1px solid #999; +} +dl { + padding: 4px 4px 4px 6px; + border: 1px solid #aaa; + background-color: #ffc; +} +dt { + color: #900; +} +#organizationLogo img, #projectLogo img, #projectLogo span{ + margin: 8px; +} +#banner { + border-bottom: 1px solid #fff; +} +.errormark, .warningmark, .donemark, .infomark { + background: url(../images/icon_error_sml.gif) no-repeat; +} + +.warningmark { + background-image: url(../images/icon_warning_sml.gif); +} + +.donemark { + background-image: url(../images/icon_success_sml.gif); +} + +.infomark { + background-image: url(../images/icon_info_sml.gif); +} + diff --git a/SpringBoot-Commons/target/site/css/print.css b/SpringBoot-Commons/target/site/css/print.css new file mode 100644 index 0000000..18fcbad --- /dev/null +++ b/SpringBoot-Commons/target/site/css/print.css @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#banner, #footer, #leftcol, #breadcrumbs, .docs #toc, .docs .courtesylinks, #leftColumn, #navColumn { + display: none !important; +} +#bodyColumn, body.docs div.docs { + margin: 0 !important; + border: none !important +} diff --git a/SpringBoot-Commons/target/site/css/site.css b/SpringBoot-Commons/target/site/css/site.css new file mode 100644 index 0000000..055e7e2 --- /dev/null +++ b/SpringBoot-Commons/target/site/css/site.css @@ -0,0 +1 @@ +/* You can override this file with your own styles */ \ No newline at end of file diff --git a/SpringBoot-Commons/target/site/dependencies.html b/SpringBoot-Commons/target/site/dependencies.html new file mode 100644 index 0000000..e6a307f --- /dev/null +++ b/SpringBoot-Commons/target/site/dependencies.html @@ -0,0 +1,3261 @@ + + + + + + SpringBoot-Commons – Project Dependencies + + + + + + + + +
+ +
+
+
+ +
+

Project Dependencies

+
+

compile

+

The following is a list of compile dependencies for this project. These dependencies are required to compile and run the application:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
GroupIdArtifactIdVersionTypeLicenses
com.aliyun.ossaliyun-sdk-oss3.8.0jar-
com.github.xiaoyminknife4j-spring-boot-starter3.0.2jarThe Apache Software License, Version 2.0
javax.activationactivation1.1.1jarCOMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
javax.xml.bindjaxb-api2.3.1jar-
org.apache.rocketmqrocketmq-spring-boot2.1.1jarApache License, Version 2.0
org.glassfish.jaxbjaxb-runtime2.3.3jarEclipse Distribution License - v 1.0
org.springframework.bootspring-boot-starter-web2.3.9.RELEASEjarApache License, Version 2.0
+
+

test

+

The following is a list of test dependencies for this project. These dependencies are only required to compile and run unit tests for the application:

+ + + + + + + + + + + + + + + + + + +
GroupIdArtifactIdVersionTypeLicenses
junitjunit4.11jarCommon Public License Version 1.0
org.springframework.bootspring-boot-starter-test2.3.9.RELEASEjarApache License, Version 2.0
+
+

provided

+

The following is a list of provided dependencies for this project. These dependencies are required to compile the application, but should be provided by default when using the library:

+ + + + + + + + + + + + +
GroupIdArtifactIdVersionTypeLicenses
org.projectlomboklombok1.18.20jarThe MIT License
+
+

Project Transitive Dependencies

+

The following is a list of transitive dependencies for this project. Transitive dependencies are the dependencies of the project dependencies.

+
+

compile

+

The following is a list of compile dependencies for this project. These dependencies are required to compile and run the application:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
GroupIdArtifactIdVersionTypeLicenses
ch.qos.logbacklogback-classic1.2.3jar-
ch.qos.logbacklogback-core1.2.3jar-
com.alibabafastjson1.2.69jarApache 2
com.aliyunaliyun-java-sdk-core3.4.0jar-
com.aliyunaliyun-java-sdk-ecs4.2.0jar-
com.aliyunaliyun-java-sdk-ram3.0.0jar-
com.aliyunaliyun-java-sdk-sts3.0.0jar-
com.fasterxmlclassmate1.5.1jar-
com.fasterxml.jackson.corejackson-annotations2.11.4jar-
com.fasterxml.jackson.corejackson-core2.11.4jar-
com.fasterxml.jackson.corejackson-databind2.11.4jar-
com.fasterxml.jackson.dataformatjackson-dataformat-yaml2.11.4jar-
com.fasterxml.jackson.datatypejackson-datatype-jdk82.11.4jar-
com.fasterxml.jackson.datatypejackson-datatype-jsr3102.11.4jar-
com.fasterxml.jackson.modulejackson-module-parameter-names2.11.4jar-
com.github.xiaoyminknife4j-annotations3.0.2jarThe Apache Software License, Version 2.0
com.github.xiaoyminknife4j-core3.0.2jarThe Apache Software License, Version 2.0
com.github.xiaoyminknife4j-spring3.0.2jarThe Apache Software License, Version 2.0
com.github.xiaoyminknife4j-spring-boot-autoconfigure3.0.2jarThe Apache Software License, Version 2.0
com.github.xiaoyminknife4j-spring-ui3.0.2jarThe Apache Software License, Version 2.0
com.google.code.findbugsjsr3053.0.2jar-
com.google.errorproneerror_prone_annotations2.2.0jarApache 2.0
com.google.guavafailureaccess1.0.1jar-
com.google.guavaguava27.0.1-androidjar-
com.google.guavalistenablefuture9999.0-empty-to-avoid-conflict-with-guavajarThe Apache Software License, Version 2.0
com.google.j2objcj2objc-annotations1.1jarThe Apache Software License, Version 2.0
com.sun.istackistack-commons-runtime3.0.11jarEclipse Distribution License - v 1.0
commons-beanutilscommons-beanutils1.9.2jarThe Apache Software License, Version 2.0
commons-clicommons-cli1.2jarThe Apache Software License, Version 2.0
commons-codeccommons-codec1.14jarApache License, Version 2.0
commons-collectionscommons-collections3.2.2jarApache License, Version 2.0
commons-digestercommons-digester1.8.1jarThe Apache Software License, Version 2.0
commons-loggingcommons-logging1.2jarThe Apache Software License, Version 2.0
commons-validatorcommons-validator1.6jarApache License, Version 2.0
io.github.classgraphclassgraph4.8.83jar-
io.nettynetty-all4.1.59.FinaljarApache License, Version 2.0
io.nettynetty-tcnative-boringssl-static2.0.36.Finaljar-
io.springfoxspringfox-bean-validators3.0.0jarThe Apache Software License, Version 2.0
io.springfoxspringfox-boot-starter3.0.0jarThe Apache Software License, Version 2.0
io.springfoxspringfox-core3.0.0jarThe Apache Software License, Version 2.0
io.springfoxspringfox-data-rest3.0.0jarThe Apache Software License, Version 2.0
io.springfoxspringfox-oas3.0.0jarThe Apache Software License, Version 2.0
io.springfoxspringfox-schema3.0.0jarThe Apache Software License, Version 2.0
io.springfoxspringfox-spi3.0.0jarThe Apache Software License, Version 2.0
io.springfoxspringfox-spring-web3.0.0jarThe Apache Software License, Version 2.0
io.springfoxspringfox-spring-webflux3.0.0jarThe Apache Software License, Version 2.0
io.springfoxspringfox-spring-webmvc3.0.0jarThe Apache Software License, Version 2.0
io.springfoxspringfox-swagger-common3.0.0jarThe Apache Software License, Version 2.0
io.springfoxspringfox-swagger23.0.0jarThe Apache Software License, Version 2.0
io.swaggerswagger-annotations1.5.22jar-
io.swaggerswagger-core1.5.22jar-
io.swaggerswagger-models1.5.22jar-
io.swagger.core.v3swagger-annotations2.1.2jar-
io.swagger.core.v3swagger-models2.1.2jar-
jakarta.annotationjakarta.annotation-api1.3.5jarEPL 2.0GPL2 w/ CPE
jakarta.xml.bindjakarta.xml.bind-api2.3.3jarEclipse Distribution License - v 1.0
javax.activationjavax.activation-api1.2.0jarCDDL/GPLv2+CE
javax.validationvalidation-api2.0.1.FinaljarApache License 2.0
net.bytebuddybyte-buddy1.10.20jarApache License, Version 2.0
org.apache.commonscommons-lang33.10jarApache License, Version 2.0
org.apache.httpcomponentshttpclient4.5.13jarApache License, Version 2.0
org.apache.httpcomponentshttpcore4.4.14jarApache License, Version 2.0
org.apache.logging.log4jlog4j-api2.13.3jar-
org.apache.logging.log4jlog4j-to-slf4j2.13.3jar-
org.apache.rocketmqrocketmq-acl4.7.1jarApache License, Version 2.0
org.apache.rocketmqrocketmq-client4.7.1jarApache License, Version 2.0
org.apache.rocketmqrocketmq-common4.7.1jarApache License, Version 2.0
org.apache.rocketmqrocketmq-logging4.7.1jarApache License, Version 2.0
org.apache.rocketmqrocketmq-remoting4.7.1jarApache License, Version 2.0
org.apache.rocketmqrocketmq-srvutil4.7.1jarApache License, Version 2.0
org.apache.tomcat.embedtomcat-embed-core9.0.43jarApache License, Version 2.0
org.apache.tomcat.embedtomcat-embed-websocket9.0.43jarApache License, Version 2.0
org.checkerframeworkchecker-compat-qual2.5.2jarGNU General Public License, version 2 (GPL2), with the classpath exceptionThe MIT License
org.codehaus.jettisonjettison1.1jar-
org.codehaus.mojoanimal-sniffer-annotations1.17jarMIT license
org.glassfishjakarta.el3.0.3jarEPL 2.0GPL2 w/ CPE
org.glassfish.jaxbtxw22.3.3jarEclipse Distribution License - v 1.0
org.javassistjavassist3.25.0-GAjar-
org.jdomjdom1.1jar-
org.slf4jjul-to-slf4j1.7.30jarMIT License
org.slf4jslf4j-api1.7.30jarMIT License
org.springframeworkspring-aop5.2.13.RELEASEjarApache License, Version 2.0
org.springframeworkspring-beans5.2.13.RELEASEjarApache License, Version 2.0
org.springframeworkspring-context5.2.13.RELEASEjarApache License, Version 2.0
org.springframeworkspring-core5.2.13.RELEASEjarApache License, Version 2.0
org.springframeworkspring-expression5.2.13.RELEASEjarApache License, Version 2.0
org.springframeworkspring-jcl5.2.13.RELEASEjarApache License, Version 2.0
org.springframeworkspring-messaging5.2.13.RELEASEjarApache License, Version 2.0
org.springframeworkspring-web5.2.13.RELEASEjarApache License, Version 2.0
org.springframeworkspring-webmvc5.2.13.RELEASEjarApache License, Version 2.0
org.springframework.bootspring-boot2.3.9.RELEASEjarApache License, Version 2.0
org.springframework.bootspring-boot-autoconfigure2.3.9.RELEASEjarApache License, Version 2.0
org.springframework.bootspring-boot-starter2.3.9.RELEASEjarApache License, Version 2.0
org.springframework.bootspring-boot-starter-json2.3.9.RELEASEjarApache License, Version 2.0
org.springframework.bootspring-boot-starter-logging2.3.9.RELEASEjarApache License, Version 2.0
org.springframework.bootspring-boot-starter-tomcat2.3.9.RELEASEjarApache License, Version 2.0
org.springframework.pluginspring-plugin-core2.0.0.RELEASEjarApache License, Version 2.0
org.springframework.pluginspring-plugin-metadata2.0.0.RELEASEjarApache License, Version 2.0
org.yamlsnakeyaml1.26jar-
staxstax-api1.0.1jarThe Apache Software License, Version 2.0
+
+

runtime

+

The following is a list of runtime dependencies for this project. These dependencies are required to run the application:

+ + + + + + + + + + + + + + + + + + +
GroupIdArtifactIdVersionTypeLicenses
com.sun.activationjakarta.activation1.2.2jarEDL 1.0
org.mapstructmapstruct1.3.1.FinaljarThe Apache Software License, Version 2.0
+
+

test

+

The following is a list of test dependencies for this project. These dependencies are only required to compile and run unit tests for the application:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
GroupIdArtifactIdVersionTypeLicenses
com.jayway.jsonpathjson-path2.4.0jarThe Apache Software License, Version 2.0
com.vaadin.external.googleandroid-json0.0.20131108.vaadin1jarApache License 2.0
net.bytebuddybyte-buddy-agent1.10.20jarApache License, Version 2.0
net.minidevaccessors-smart1.2jar-
net.minidevjson-smart2.3jar-
org.apiguardianapiguardian-api1.1.0jarThe Apache License, Version 2.0
org.assertjassertj-core3.16.1jar-
org.hamcresthamcrest2.2jarBSD License 3
org.hamcresthamcrest-core2.2jarBSD License 3
org.junit.jupiterjunit-jupiter5.6.3jarEclipse Public License v2.0
org.junit.jupiterjunit-jupiter-api5.6.3jarEclipse Public License v2.0
org.junit.jupiterjunit-jupiter-engine5.6.3jarEclipse Public License v2.0
org.junit.jupiterjunit-jupiter-params5.6.3jarEclipse Public License v2.0
org.junit.platformjunit-platform-commons1.6.3jarEclipse Public License v2.0
org.junit.platformjunit-platform-engine1.6.3jarEclipse Public License v2.0
org.junit.vintagejunit-vintage-engine5.6.3jarEclipse Public License v2.0
org.mockitomockito-core3.3.3jarThe MIT License
org.mockitomockito-junit-jupiter3.3.3jarThe MIT License
org.objenesisobjenesis2.6jar-
org.opentest4jopentest4j1.2.0jarThe Apache License, Version 2.0
org.ow2.asmasm5.0.4jarBSD
org.skyscreamerjsonassert1.5.0jar-
org.springframeworkspring-test5.2.13.RELEASEjarApache License, Version 2.0
org.springframework.bootspring-boot-test2.3.9.RELEASEjarApache License, Version 2.0
org.springframework.bootspring-boot-test-autoconfigure2.3.9.RELEASEjarApache License, Version 2.0
org.xmlunitxmlunit-core2.7.0jarThe Apache Software License, Version 2.0
+
+

Project Dependency Graph

+ + +
+

Dependency Tree

+
+
+

Licenses

+

Apache 2.0: error-prone annotations

+

The Apache License, Version 2.0: org.apiguardian:apiguardian-api, org.opentest4j:opentest4j

+

BSD License 3: Hamcrest, Hamcrest Core

+

MIT License: JUL to SLF4J bridge, SLF4J API Module

+

Eclipse Public License v2.0: JUnit Jupiter (Aggregator), JUnit Jupiter API, JUnit Jupiter Engine, JUnit Jupiter Params, JUnit Platform Commons, JUnit Platform Engine API, JUnit Vintage Engine

+

GPL2 w/ CPE: Jakarta Annotations API, Jakarta Expression Language 3.0

+

CDDL/GPLv2+CE: JavaBeans Activation Framework API jar

+

Apache 2: fastjson

+

BSD: ASM Core

+

Unknown: JDOM, Netty/TomcatNative [BoringSSL - Static]

+

EDL 1.0: Jakarta Activation

+

Apache License 2.0: Bean Validation API, JSON library from Android SDK

+

The MIT License: Checker Qual, Project Lombok, mockito-core, mockito-junit-jupiter

+

Apache License, Version 2.0: Apache Commons Codec, Apache Commons Collections, Apache Commons Lang, Apache Commons Validator, Apache HttpClient, Apache HttpCore, Byte Buddy (without dependencies), Byte Buddy agent, Netty/All-in-One, RocketMQ Spring Boot AutoConfigure, Spring AOP, Spring Beans, Spring Commons Logging Bridge, Spring Context, Spring Core, Spring Expression Language (SpEL), Spring Messaging, Spring Plugin - Core, Spring Plugin - Metadata Extension, Spring TestContext Framework, Spring Web, Spring Web MVC, SpringBoot-Commons, rocketmq-acl 4.7.1, rocketmq-client 4.7.1, rocketmq-common 4.7.1, rocketmq-logging 4.7.1, rocketmq-remoting 4.7.1, rocketmq-srvutil 4.7.1, spring-boot, spring-boot-autoconfigure, spring-boot-starter, spring-boot-starter-json, spring-boot-starter-logging, spring-boot-starter-test, spring-boot-starter-tomcat, spring-boot-starter-web, spring-boot-test, spring-boot-test-autoconfigure, tomcat-embed-core, tomcat-embed-websocket

+

COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0: JavaBeans(TM) Activation Framework

+

GNU General Public License, version 2 (GPL2), with the classpath exception: Checker Qual

+

Eclipse Distribution License - v 1.0: JAXB Runtime, Jakarta XML Binding API, TXW2 Runtime, istack common utility code runtime

+

EPL 2.0: Jakarta Annotations API, Jakarta Expression Language 3.0

+

MIT license: Animal Sniffer Annotations

+

Common Public License Version 1.0: JUnit

+

The Apache Software License, Version 2.0: Apache Commons BeanUtils, Apache Commons Logging, Commons CLI, Commons Digester, Guava ListenableFuture only, J2ObjC Annotations, MapStruct Core, StAX API, knife4j-annotations, knife4j-core, knife4j-spring, knife4j-spring-boot-autoconfigure, knife4j-spring-boot-starter, knife4j-spring-ui, org.xmlunit:xmlunit-core, project ':json-path', springfox-bean-validators, springfox-boot-starter, springfox-core, springfox-data-rest, springfox-oas, springfox-schema, springfox-spi, springfox-spring-web, springfox-spring-webflux, springfox-spring-webmvc, springfox-swagger-common, springfox-swagger2

+
+

Dependency File Details

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FilenameSizeEntriesClassesPackagesJava VersionDebug Information
logback-classic-1.2.3.jar290.3 kB234175271.6Yes
logback-core-1.2.3.jar471.9 kB419373361.6Yes
fastjson-1.2.69.jar671.6 kB287252181.6Yes
aliyun-java-sdk-core-3.4.0.jar116.3 kB9977101.6Yes
aliyun-java-sdk-ecs-4.2.0.jar788.1 kB73972521.6Yes
aliyun-java-sdk-ram-3.0.0.jar215.5 kB25924521.6Yes
aliyun-java-sdk-sts-3.0.0.jar13.3 kB261221.6Yes
aliyun-sdk-oss-3.8.0.jar626.8 kB475449101.6Yes
classmate-1.5.1.jar67.8 kB55405-Yes
jackson-annotations-2.11.4.jar72.1 kB81692-Yes
jackson-core-2.11.4.jar351.5 kB14411813-Yes
jackson-databind-2.11.4.jar1.4 MB69365822-Yes
jackson-dataformat-yaml-2.11.4.jar46.9 kB35163-Yes
jackson-datatype-jdk8-2.11.4.jar34.3 kB37232-Yes
jackson-datatype-jsr310-2.11.4.jar111 kB76576-Yes
jackson-module-parameter-names-2.11.4.jar9.3 kB1952-Yes
knife4j-annotations-3.0.2.jar6.7 kB20811.8No
knife4j-core-3.0.2.jar25.3 kB372051.8Yes
knife4j-spring-3.0.2.jar51.9 kB483061.8Yes
knife4j-spring-boot-autoconfigure-3.0.2.jar9.7 kB20421.8Yes
knife4j-spring-boot-starter-3.0.2.jar1.8 kB700-No
knife4j-spring-ui-3.0.2.jar2.9 MB8000-No
jsr305-3.0.2.jar19.9 kB463531.5Yes
error_prone_annotations-2.2.0.jar13.7 kB342221.7No
failureaccess-1.0.1.jar4.6 kB15211.7Yes
guava-27.0.1-android.jar2.6 MB19161886181.7Yes
listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar2.2 kB700-No
j2objc-annotations-1.1.jar8.8 kB231211.5Yes
json-path-2.4.0.jar223.2 kB191174121.6Yes
jakarta.activation-1.2.2.jar68.5 kB61434-Yes
istack-commons-runtime-3.0.11.jar29.9 kB44234-Yes
android-json-0.0.20131108.vaadin1.jar18.3 kB12811.5Yes
commons-beanutils-1.9.2.jar233.9 kB15413751.5Yes
commons-cli-1.2.jar41.1 kB352211.4Yes
commons-codec-1.14.jar347.7 kB24910271.7Yes
commons-collections-3.2.2.jar588.3 kB484460121.3Yes
commons-digester-1.8.1.jar146.1 kB11910061.2Yes
commons-logging-1.2.jar61.8 kB422821.2Yes
commons-validator-1.6.jar186.1 kB1027741.6Yes
classgraph-4.8.83.jar504.7 kB26023213-Yes
netty-all-4.1.59.Final.jar4.3 MB29242805811.6Yes
netty-tcnative-boringssl-static-2.0.36.Final.jar4 MB421911.6Yes
springfox-bean-validators-3.0.0.jar38.6 kB302041.8Yes
springfox-boot-starter-3.0.0.jar13.1 kB201211.8Yes
springfox-core-3.0.0.jar262.8 kB19218071.8Yes
springfox-data-rest-3.0.0.jar71.3 kB483931.8Yes
springfox-oas-3.0.0.jar78.5 kB544541.8Yes
springfox-schema-3.0.0.jar102.5 kB655561.8Yes
springfox-spi-3.0.0.jar55.2 kB534361.8Yes
springfox-spring-web-3.0.0.jar188.5 kB948071.8Yes
springfox-spring-webflux-3.0.0.jar13.9 kB16821.8Yes
springfox-spring-webmvc-3.0.0.jar14.5 kB17921.8Yes
springfox-swagger-common-3.0.0.jar116.3 kB624971.8Yes
springfox-swagger2-3.0.0.jar109.8 kB756641.8Yes
swagger-annotations-1.5.22.jar21.7 kB413111.7Yes
swagger-core-1.5.22.jar116.6 kB937671.7Yes
swagger-models-1.5.22.jar155 kB1099461.7Yes
swagger-annotations-2.1.2.jar34.8 kB6844131.8Yes
swagger-models-2.1.2.jar118.2 kB8562121.8Yes
jakarta.annotation-api-1.3.5.jar25.1 kB281531.8Yes
jakarta.xml.bind-api-2.3.3.jar115.6 kB1371117-Yes
activation-1.1.1.jar69.4 kB503831.4Yes
javax.activation-api-1.2.0.jar56.7 kB413111.5Yes
validation-api-2.0.1.Final.jar93.1 kB16314391.8Yes
jaxb-api-2.3.1.jar128.1 kB1361117-Yes
junit-4.11.jar245 kB266233281.5Yes
byte-buddy-1.10.20.jar3.5 MB2512245737-Yes
byte-buddy-agent-1.10.20.jar259.2 kB81632-Yes
accessors-smart-1.2.jar30 kB241321.6Yes
json-smart-2.3.jar120.3 kB1069251.6Yes
commons-lang3-3.10.jar523.4 kB314288141.8Yes
httpclient-4.5.13.jar780.3 kB511470241.6Yes
httpcore-4.4.14.jar328.4 kB283253171.6Yes
log4j-api-2.13.3.jar292.3 kB2141809-Yes
log4j-to-slf4j-2.13.3.jar17.5 kB22611.8Yes
rocketmq-acl-4.7.1.jar47 kB382231.8Yes
rocketmq-client-4.7.1.jar390 kB224190211.6Yes
rocketmq-common-4.7.1.jar295.5 kB269229271.6Yes
rocketmq-logging-4.7.1.jar63.8 kB543921.6Yes
rocketmq-remoting-4.7.1.jar123.6 kB1028361.6Yes
rocketmq-spring-boot-2.1.1.jar71.7 kB553441.8Yes
rocketmq-srvutil-4.7.1.jar13.1 kB18411.8Yes
tomcat-embed-core-9.0.43.jar3.4 MB1731152079-Yes
tomcat-embed-websocket-9.0.43.jar271.8 kB2051786-Yes
apiguardian-api-1.1.0.jar2.4 kB832-Yes
assertj-core-3.16.1.jar4.7 MB3215312861-Yes
checker-compat-qual-2.5.2.jar5.8 kB171011.6No
jettison-1.1.jar67.8 kB554051.1Yes
animal-sniffer-annotations-1.17.jar3.4 kB12111.7No
jakarta.el-3.0.3.jar237.8 kB18216261.7Yes
jaxb-runtime-2.3.3.jar1 MB82564926-Yes
txw2-2.3.3.jar72 kB69544-Yes
hamcrest-2.2.jar123.4 kB122108111.7Yes
hamcrest-core-2.2.jar1.5 kB8111.7Yes
javassist-3.25.0-GA.jar780.3 kB449425171.7Yes
jdom-1.1.jar153.1 kB897681.2Yes
junit-jupiter-5.6.3.jar6.4 kB511-No
junit-jupiter-api-5.6.3.jar154 kB1501358-Yes
junit-jupiter-engine-5.6.3.jar209.3 kB1301139-Yes
junit-jupiter-params-5.6.3.jar562.3 kB37033622-Yes
junit-platform-commons-1.6.3.jar96.7 kB61417-Yes
junit-platform-engine-1.6.3.jar174.1 kB1391239-Yes
junit-vintage-engine-5.6.3.jar63.8 kB47336-Yes
mapstruct-1.3.1.Final.jar23 kB433131.8Yes
mockito-core-3.3.3.jar592.3 kB636563651.8Yes
mockito-junit-jupiter-3.3.3.jar4.5 kB9211.8Yes
objenesis-2.6.jar55.7 kB5943101.6Yes
opentest4j-1.2.0.jar7.7 kB1172-Yes
asm-5.0.4.jar53.3 kB302521.2No
lombok-1.18.20.jar1.9 MB102916313-Yes
jsonassert-1.5.0.jar30.3 kB322031.6Yes
jul-to-slf4j-1.7.30.jar4.6 kB11111.5Yes
slf4j-api-1.7.30.jar41.5 kB463441.5Yes
spring-aop-5.2.13.RELEASE.jar372.8 kB306277171.8Yes
spring-beans-5.2.13.RELEASE.jar688.7 kB414384131.8Yes
spring-context-5.2.13.RELEASE.jar1.2 MB967880641.8Yes
spring-core-5.2.13.RELEASE.jar1.4 MB1023965471.8Yes
spring-expression-5.2.13.RELEASE.jar282.2 kB16415061.8Yes
spring-jcl-5.2.13.RELEASE.jar24 kB281721.8Yes
spring-messaging-5.2.13.RELEASE.jar549.6 kB361332221.8Yes
spring-test-5.2.13.RELEASE.jar685.4 kB516462391.8Yes
spring-web-5.2.13.RELEASE.jar1.4 MB996926551.8Yes
spring-webmvc-5.2.13.RELEASE.jar956.7 kB586541281.8Yes
spring-boot-2.3.9.RELEASE.jar1.1 MB837725711.8Yes
spring-boot-autoconfigure-2.3.9.RELEASE.jar1.5 MB12201104991.8Yes
spring-boot-starter-2.3.9.RELEASE.jar4.8 kB400-No
spring-boot-starter-json-2.3.9.RELEASE.jar4.7 kB400-No
spring-boot-starter-logging-2.3.9.RELEASE.jar4.8 kB400-No
spring-boot-starter-test-2.3.9.RELEASE.jar4.8 kB400-No
spring-boot-starter-tomcat-2.3.9.RELEASE.jar4.8 kB400-No
spring-boot-starter-web-2.3.9.RELEASE.jar4.8 kB400-No
spring-boot-test-2.3.9.RELEASE.jar217.2 kB164138141.8Yes
spring-boot-test-autoconfigure-2.3.9.RELEASE.jar175.6 kB186153191.8Yes
spring-plugin-core-2.0.0.RELEASE.jar28.8 kB351631.8Yes
spring-plugin-metadata-2.0.0.RELEASE.jar9.9 kB17411.8Yes
xmlunit-core-2.7.0.jar168.4 kB17115581.6Yes
snakeyaml-1.26.jar309 kB253216201.7Yes
stax-api-1.0.1.jar26.5 kB484051.2Yes
TotalSizeEntriesClassesPackagesJava VersionDebug Information
13856.9 MB355313107216061.8123
compile: 107compile: 45.9 MBcompile: 27645compile: 24662compile: 1236-compile: 95
test: 28test: 9 MBtest: 6753test: 6173test: 350-test: 25
runtime: 2runtime: 91.5 kBruntime: 104runtime: 74runtime: 7-runtime: 2
provided: 1provided: 1.9 MBprovided: 1029provided: 163provided: 13-provided: 1
+
+
+
+
+
+ + + diff --git a/SpringBoot-Commons/target/site/dependency-info.html b/SpringBoot-Commons/target/site/dependency-info.html new file mode 100644 index 0000000..ddab553 --- /dev/null +++ b/SpringBoot-Commons/target/site/dependency-info.html @@ -0,0 +1,115 @@ + + + + + + SpringBoot-Commons – Dependency Information + + + + + + + + +
+ +
+
+
+
+

Dependency Information

+
+

Apache Maven

+
+
<dependency>
+  <groupId>com.fancv</groupId>
+  <artifactId>SpringBoot-Commons</artifactId>
+  <version>1.0-SNAPSHOT</version>
+</dependency>
+
+

Apache Buildr

+
+
'com.fancv:SpringBoot-Commons:jar:1.0-SNAPSHOT'
+
+

Apache Ivy

+
+
<dependency org="com.fancv" name="SpringBoot-Commons" rev="1.0-SNAPSHOT">
+  <artifact name="SpringBoot-Commons" type="jar" />
+</dependency>
+
+

Groovy Grape

+
+
@Grapes(
+@Grab(group='com.fancv', module='SpringBoot-Commons', version='1.0-SNAPSHOT')
+)
+
+

Gradle/Grails

+
+
compile 'com.fancv:SpringBoot-Commons:1.0-SNAPSHOT'
+
+

Scala SBT

+
+
libraryDependencies += "com.fancv" % "SpringBoot-Commons" % "1.0-SNAPSHOT"
+
+

Leiningen

+
+
[com.fancv/SpringBoot-Commons "1.0-SNAPSHOT"]
+
+
+
+
+
+ + + diff --git a/SpringBoot-Commons/target/site/dependency-management.html b/SpringBoot-Commons/target/site/dependency-management.html new file mode 100644 index 0000000..e69de29 diff --git a/SpringBoot-Commons/target/site/images/close.gif b/SpringBoot-Commons/target/site/images/close.gif new file mode 100644 index 0000000..1c26bbc Binary files /dev/null and b/SpringBoot-Commons/target/site/images/close.gif differ diff --git a/SpringBoot-Commons/target/site/images/collapsed.gif b/SpringBoot-Commons/target/site/images/collapsed.gif new file mode 100644 index 0000000..6e71084 Binary files /dev/null and b/SpringBoot-Commons/target/site/images/collapsed.gif differ diff --git a/SpringBoot-Commons/target/site/images/expanded.gif b/SpringBoot-Commons/target/site/images/expanded.gif new file mode 100644 index 0000000..0fef3d8 Binary files /dev/null and b/SpringBoot-Commons/target/site/images/expanded.gif differ diff --git a/SpringBoot-Commons/target/site/images/external.png b/SpringBoot-Commons/target/site/images/external.png new file mode 100644 index 0000000..3f999fc Binary files /dev/null and b/SpringBoot-Commons/target/site/images/external.png differ diff --git a/SpringBoot-Commons/target/site/images/icon_error_sml.gif b/SpringBoot-Commons/target/site/images/icon_error_sml.gif new file mode 100644 index 0000000..61132ef Binary files /dev/null and b/SpringBoot-Commons/target/site/images/icon_error_sml.gif differ diff --git a/SpringBoot-Commons/target/site/images/icon_info_sml.gif b/SpringBoot-Commons/target/site/images/icon_info_sml.gif new file mode 100644 index 0000000..c6cb9ad Binary files /dev/null and b/SpringBoot-Commons/target/site/images/icon_info_sml.gif differ diff --git a/SpringBoot-Commons/target/site/images/icon_success_sml.gif b/SpringBoot-Commons/target/site/images/icon_success_sml.gif new file mode 100644 index 0000000..52e85a4 Binary files /dev/null and b/SpringBoot-Commons/target/site/images/icon_success_sml.gif differ diff --git a/SpringBoot-Commons/target/site/images/icon_warning_sml.gif b/SpringBoot-Commons/target/site/images/icon_warning_sml.gif new file mode 100644 index 0000000..873bbb5 Binary files /dev/null and b/SpringBoot-Commons/target/site/images/icon_warning_sml.gif differ diff --git a/SpringBoot-Commons/target/site/images/logos/build-by-maven-black.png b/SpringBoot-Commons/target/site/images/logos/build-by-maven-black.png new file mode 100644 index 0000000..919fd0f Binary files /dev/null and b/SpringBoot-Commons/target/site/images/logos/build-by-maven-black.png differ diff --git a/SpringBoot-Commons/target/site/images/logos/build-by-maven-white.png b/SpringBoot-Commons/target/site/images/logos/build-by-maven-white.png new file mode 100644 index 0000000..7d44c9c Binary files /dev/null and b/SpringBoot-Commons/target/site/images/logos/build-by-maven-white.png differ diff --git a/SpringBoot-Commons/target/site/images/logos/maven-feather.png b/SpringBoot-Commons/target/site/images/logos/maven-feather.png new file mode 100644 index 0000000..b5ada83 Binary files /dev/null and b/SpringBoot-Commons/target/site/images/logos/maven-feather.png differ diff --git a/SpringBoot-Commons/target/site/images/newwindow.png b/SpringBoot-Commons/target/site/images/newwindow.png new file mode 100644 index 0000000..6287f72 Binary files /dev/null and b/SpringBoot-Commons/target/site/images/newwindow.png differ diff --git a/SpringBoot-Commons/target/test-classes/com/fancv/AppTest.class b/SpringBoot-Commons/target/test-classes/com/fancv/AppTest.class new file mode 100644 index 0000000..13b8f85 Binary files /dev/null and b/SpringBoot-Commons/target/test-classes/com/fancv/AppTest.class differ diff --git a/SpringBoot-DynamicDataSource/pom.xml b/SpringBoot-DynamicDataSource/pom.xml new file mode 100644 index 0000000..aeb30f3 --- /dev/null +++ b/SpringBoot-DynamicDataSource/pom.xml @@ -0,0 +1,65 @@ + + + + SpringBootCodeBase + com.fancv + 1.0-SNAPSHOT + + 4.0.0 + + SpringBoot-DynamicDataSource + + + 11 + 11 + 1.8 + 3.2.0 + 3.1.0 + 1.2.62 + 2.10.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.3.9.RELEASE + + + com.alibaba + druid-spring-boot-starter + 1.1.17 + + + com.baomidou + mybatis-plus-extension + 3.5.1 + compile + + + org.springframework.boot + spring-boot-starter-aop + 2.3.9.RELEASE + + + org.aspectj + aspectjweaver + + + mysql + mysql-connector-java + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/DemoApplication.java b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/DemoApplication.java new file mode 100644 index 0000000..198b9dd --- /dev/null +++ b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/DemoApplication.java @@ -0,0 +1,16 @@ +package com.example.demo; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; + +@MapperScan("com.example.demo.mapper") +@SpringBootApplication(exclude = DataSourceAutoConfiguration.class) +public class DemoApplication { + + public static void main(String[] args) { + SpringApplication.run(DemoApplication.class, args); + } + +} diff --git a/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/controller/DemoController.java b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/controller/DemoController.java new file mode 100644 index 0000000..86af1d9 --- /dev/null +++ b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/controller/DemoController.java @@ -0,0 +1,55 @@ +package com.example.demo.controller; + +import com.example.demo.service.impl.UserService; +import com.example.demo.utils.BaseUserDTO; +import com.example.demo.utils.UserContext; +import org.aspectj.lang.annotation.AdviceName; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; + +@RestController +@RequestMapping("1") +public class DemoController { + + + @Autowired + UserService userService; + + @GetMapping ("login") + public String userLogin(@RequestParam(defaultValue = "001") String userId) { + System.out.println("根据token信息查询用户信息"); + + BaseUserDTO baseUserDTO = new BaseUserDTO(); + baseUserDTO.setId(015); + baseUserDTO.setUserNmae("015"); + baseUserDTO.setPermissions(new ArrayList<>()); + // 校验权限 + System.out.println("根据userId 查询权限"); + baseUserDTO.addPeemission("1"); + baseUserDTO.addPeemission("2"); + + UserContext.setBaseUser(baseUserDTO); + + return userService.login(); + } + + @GetMapping ("master") + public String userLogin2(@RequestParam(defaultValue = "001") String userId) { + System.out.println("根据token信息查询用户信息"); + + BaseUserDTO baseUserDTO = new BaseUserDTO(); + baseUserDTO.setId(015); + baseUserDTO.setUserNmae("master"); + baseUserDTO.setPermissions(new ArrayList<>()); + // 校验权限 + System.out.println("根据userId 查询权限"); + baseUserDTO.addPeemission("1"); + baseUserDTO.addPeemission("2"); + + UserContext.setBaseUser(baseUserDTO); + + return userService.login(); + } +} diff --git a/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/datasource/DataSourceConfig.java b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/datasource/DataSourceConfig.java new file mode 100644 index 0000000..24e4677 --- /dev/null +++ b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/datasource/DataSourceConfig.java @@ -0,0 +1,57 @@ +package com.example.demo.datasource; + +import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; + +import javax.sql.DataSource; +import java.util.HashMap; +import java.util.Map; + +@Configuration +@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class }) // 排除 DataSourceAutoConfiguration 的自动配置,避免环形调用 +public class DataSourceConfig { + /** + * 默认数据源 + * + * @return + */ + @Bean(DataSourceConstant.DATA_SOURCE_MASTER) + @ConfigurationProperties("spring.datasource.druid.master") + public DataSource dataSourceMaster() { + return DruidDataSourceBuilder.create().build(); + } + + /** + * 递增数据源 + * + * @return + */ + @Bean(DataSourceConstant.DATA_SOURCE_DB_1) + @ConfigurationProperties("spring.datasource.druid.db1") + public DataSource dataSourceDb1() { + return DruidDataSourceBuilder.create().build(); + } + + + /** + * 设置动态数据源为主数据源 + * + * @return + */ + @Bean + @Primary + public DynamicDataSource dataSource() { + Map dataSourceMap = new HashMap<>(); + dataSourceMap.put("master", dataSourceMaster()); + dataSourceMap.put("015", dataSourceDb1()); + DynamicDataSource dynamicDataSource = new DynamicDataSource(); + // 使用 Map 保存多个数据源,并设置到动态数据源对象中,这个值最终会在afterPropertiesSet中被设置到resolvedDataSources上 + dynamicDataSource.setTargetDataSources(dataSourceMap); + return dynamicDataSource; + } +} diff --git a/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/datasource/DataSourceConstant.java b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/datasource/DataSourceConstant.java new file mode 100644 index 0000000..d7bb52a --- /dev/null +++ b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/datasource/DataSourceConstant.java @@ -0,0 +1,19 @@ +package com.example.demo.datasource; + +public class DataSourceConstant { + private DataSourceConstant() { + } + + /** + * 这里的命名统一在配置文件命名的基础上加dataSource前缀且改小驼峰 + * 默认数据源名称 + */ + public static final String DATA_SOURCE_MASTER = "dataSourceMaster"; + + /** + * 递增可配数据源名称 + * 这里的命名统一在配置文件命名的基础上加dataSource前缀且改小驼峰 + * 后面可接着 db2... dbn 也可以根据 + */ + public static final String DATA_SOURCE_DB_1 = "dataSourceDb1"; +} diff --git a/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/datasource/DynamicDataSource.java b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/datasource/DynamicDataSource.java new file mode 100644 index 0000000..89b0f6d --- /dev/null +++ b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/datasource/DynamicDataSource.java @@ -0,0 +1,52 @@ +package com.example.demo.datasource; + +import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; +import org.springframework.stereotype.Component; + +import javax.sql.DataSource; +import java.util.Map; + +/** + * 动态数据源 + * + * @author 李嘉 + * @version 1.0 + * @Description 动态数据源 + * @date 2020/5/18 23:26 + */ +public class DynamicDataSource extends AbstractRoutingDataSource { + + /** + * 如果不希望数据源在启动配置时就加载好,可以定制这个方法,从任何你希望的地方读取并返回数据源 + * 比如从数据库、文件、外部接口等读取数据源信息,并最终返回一个DataSource实现类对象即可 + * @return + */ + @Override + protected DataSource determineTargetDataSource() { + return super.determineTargetDataSource(); + } + + /** + * 如果希望所有数据源在启动配置时就加载好,这里通过设置数据源Key值来切换数据,定制这个方法 + * @return + */ + @Override + protected Object determineCurrentLookupKey() { + return DynamicDataSourceContextHolder.getDataSourceKey(); + } + + /** + * 设置默认数据源 + * @param defaultDataSource + */ + public void setDefaultDataSource(Object defaultDataSource) { + super.setDefaultTargetDataSource(defaultDataSource); + } + + public void setDataSources(Map dataSources) { + super.setTargetDataSources(dataSources); + // TODO 将数据源的 key 放到数据源上下文的 key 集合中,用于切换时判断数据源是否有效 + DynamicDataSourceContextHolder.addDataSourceKeys(dataSources.keySet()); + } + +} diff --git a/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/datasource/DynamicDataSourceAspect.java b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/datasource/DynamicDataSourceAspect.java new file mode 100644 index 0000000..1b7426e --- /dev/null +++ b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/datasource/DynamicDataSourceAspect.java @@ -0,0 +1,62 @@ +package com.example.demo.datasource; + +import com.example.demo.utils.BaseUserDTO; +import com.example.demo.utils.UserContext; +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +/** + * 动态数据源切面拦截 + * + * @author 李嘉 + * @version 1.0 + * @Description 动态数据源切面拦截 + * @date 2020/5/19 00:29 + */ +@Slf4j +@Component +@Aspect +@Order(1) // 请注意:这里order一定要小于tx:annotation-driven的order,即先执行DynamicDataSourceAspectAdvice切面,再执行事务切面,才能获取到最终的数据源 +@EnableAspectJAutoProxy(proxyTargetClass = true) +public class DynamicDataSourceAspect { + //前置通知 + @Before(value="execution(* com.example.demo.service.impl.*.*(..))") + public void before(){ + System.out.println("前置通知"); + } + + @Around(value = "execution(* com.example.demo.service.impl.*.*(..))") + public Object doAround(ProceedingJoinPoint pjp) throws Throwable { + try { + BaseUserDTO user = UserContext.getUser(); + Integer r = user.getId(); + String nb = user.getUserNmae(); + DynamicDataSourceContextHolder.setDataSourceKey(nb); + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + // DynamicDataSourceContextHolder.clearDataSourceKey(); + } + Object proceed = null; + try { +// 进行方法的执行 + proceed = pjp.proceed(); + System.out.println("方法返回时"); + } catch (Exception e) { + e.printStackTrace(); + System.out.println("方法异常时" + e); + }finally{ + System.out.println("后置方法"); + } + + //将方法执行的返回值返回 + return proceed; + } + +} diff --git a/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/datasource/DynamicDataSourceContextHolder.java b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/datasource/DynamicDataSourceContextHolder.java new file mode 100644 index 0000000..b9e7aa1 --- /dev/null +++ b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/datasource/DynamicDataSourceContextHolder.java @@ -0,0 +1,77 @@ +package com.example.demo.datasource; + + +import org.apache.commons.lang3.StringUtils; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +/** + * 动态数据源上下文 + * + * @author 李嘉 + * @version 1.0 + * @Description 动态数据源上下文 + * @date 2020/5/18 23:33 + */ +public class DynamicDataSourceContextHolder { + + private static final ThreadLocal contextHolder = new ThreadLocal() { + /** + * 将 master 数据源的 key作为默认数据源的 key + */ + @Override + protected String initialValue() { + return "master"; + } + }; + + /** + * 数据源的 key集合,用于切换时判断数据源是否存在 + */ + public static List dataSourceKeys = new ArrayList<>(); + + /** + * 切换数据源 + * @param key 数据源 + */ + public static void setDataSourceKey(String key) { + if (!StringUtils.isEmpty(key)) { + contextHolder.set(key); + } + } + + /** + * 获取数据源 + * @return + */ + public static String getDataSourceKey() { + return contextHolder.get(); + } + + /** + * 重置数据源 + */ + public static void clearDataSourceKey() { + contextHolder.remove(); + } + + /** + * 判断是否包含数据源 + * @param key 数据源 + * @return + */ + public static boolean containDataSourceKey(String key) { + return dataSourceKeys.contains(key); + } + + /** + * 添加数据源Keys + * @param keys + * @return + */ + public static boolean addDataSourceKeys(Collection keys) { + return dataSourceKeys.addAll(keys); + } +} diff --git a/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/datasource/DynamicDataSourceInit.java b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/datasource/DynamicDataSourceInit.java new file mode 100644 index 0000000..ea73b8a --- /dev/null +++ b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/datasource/DynamicDataSourceInit.java @@ -0,0 +1,57 @@ +//package com.example.demo.datasource; +// +//import com.example.demo.model.TenantInfo; +//import com.example.demo.service.ITenantInfoService; +//import com.example.demo.utils.SpringContextUtils; +//import com.zaxxer.hikari.HikariDataSource; +//import lombok.extern.slf4j.Slf4j; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.context.annotation.Bean; +//import org.springframework.context.annotation.Configuration; +// +//import java.util.HashMap; +//import java.util.List; +//import java.util.Map; +// +///** +// * 动态数据源初始化 +// * +// * @author 李嘉 +// * @version 1.0 +// * @Description 动态数据源初始化 +// * @date 2020/5/19 00:08 +// */ +//@Slf4j +//@Configuration +//public class DynamicDataSourceInit { +// +// @Autowired +// private ITenantInfoService tenantInfoService; +// +// @Bean +// public void initDataSource() { +// log.info("======初始化动态数据源====="); +// DynamicDataSource dynamicDataSource = (DynamicDataSource) SpringContextUtils.getBean("dynamicDataSource"); +// HikariDataSource master = (HikariDataSource) SpringContextUtils.getBean("master"); +// Map dataSourceMap = new HashMap<>(); +// dataSourceMap.put("master", master); +// +// List tenantList = tenantInfoService.list(); +// for (TenantInfo tenantInfo : tenantList) { +// log.info(tenantInfo.toString()); +// HikariDataSource dataSource = new HikariDataSource(); +// dataSource.setDriverClassName(tenantInfo.getDatasourceDriver()); +// dataSource.setJdbcUrl(tenantInfo.getDatasourceUrl()); +// dataSource.setUsername(tenantInfo.getDatasourceUsername()); +// dataSource.setPassword(tenantInfo.getDatasourcePassword()); +// dataSource.setDataSourceProperties(master.getDataSourceProperties()); +// dataSourceMap.put(tenantInfo.getTenantId(), dataSource); +// } +// // 设置数据源 +// dynamicDataSource.setDataSources(dataSourceMap); +// /** +// * 必须执行此操作,才会重新初始化AbstractRoutingDataSource 中的 resolvedDataSources,也只有这样,动态切换才会起效 +// */ +// dynamicDataSource.afterPropertiesSet(); +// } +//} diff --git a/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/datasource/MyBatisConfig.java b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/datasource/MyBatisConfig.java new file mode 100644 index 0000000..f43cb17 --- /dev/null +++ b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/datasource/MyBatisConfig.java @@ -0,0 +1,43 @@ +package com.example.demo.datasource; + +import org.apache.ibatis.session.SqlSessionFactory; +import org.mybatis.spring.SqlSessionFactoryBean; +import org.mybatis.spring.SqlSessionTemplate; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; + +import javax.annotation.Resource; + +@Configuration +public class MyBatisConfig { + + @Resource + private DynamicDataSource routingDataSource; + + /** + * routingDataSource sqlSessionFactory + * + * @return + */ + @Bean + public SqlSessionFactory sqlSessionFactory() throws Exception { + SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); + sqlSessionFactoryBean.setDataSource(routingDataSource); + sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/*.xml")); + sqlSessionFactoryBean.setTypeAliasesPackage("com.example.demo.mapper"); + return sqlSessionFactoryBean.getObject(); + } + + /** + * 注册 sqlSessionTemplate + * + * @param sqlSessionFactory + * @return + */ + @Bean + public SqlSessionTemplate financialMasterSqlSessionTemplate(SqlSessionFactory sqlSessionFactory) { + return new SqlSessionTemplate(sqlSessionFactory); + } + +} \ No newline at end of file diff --git a/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/datasource/MybatisPlusConfig.java b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/datasource/MybatisPlusConfig.java new file mode 100644 index 0000000..b545aa2 --- /dev/null +++ b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/datasource/MybatisPlusConfig.java @@ -0,0 +1,96 @@ +/* +package com.example.demo.datasource; + +import com.baomidou.mybatisplus.core.parser.ISqlParser; +import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean; +import org.apache.ibatis.plugin.Interceptor; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.jdbc.DataSourceBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import javax.sql.DataSource; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +*/ +/** + * MyBatisPlus配置 + * + * @author 李嘉 + * @version 1.0 + * @Description MyBatisPlus配置 + * @date 2020/5/18 23:50 + *//* + +@EnableTransactionManagement +@Configuration +@MapperScan({"com.example.demo.dao","com.example.demo.*.*.mapper"}) +public class MybatisPlusConfig { + + @Bean("master") + @Primary + @ConfigurationProperties(prefix = "spring.datasource.hikari") + public DataSource master() { + return DataSourceBuilder.create().build(); + } + + @Bean("dynamicDataSource") + public DataSource dynamicDataSource() { + DynamicDataSource dynamicDataSource = new DynamicDataSource(); + Map dataSourceMap = new HashMap<>(); + dataSourceMap.put("master", master()); + // 将 master 数据源作为默认指定的数据源 + dynamicDataSource.setDefaultDataSource(master()); + // 将 master 和 slave 数据源作为指定的数据源 + dynamicDataSource.setDataSources(dataSourceMap); + return dynamicDataSource; + } + + @Bean + public MybatisSqlSessionFactoryBean sqlSessionFactoryBean() throws Exception { + MybatisSqlSessionFactoryBean sessionFactory = new MybatisSqlSessionFactoryBean(); + */ +/** + * 重点,使分页插件生效 + *//* + + Interceptor[] plugins = new Interceptor[1]; + plugins[0] = paginationInterceptor(); + sessionFactory.setPlugins(plugins); + //配置数据源,此处配置为关键配置,如果没有将 dynamicDataSource作为数据源则不能实现切换 + sessionFactory.setDataSource(dynamicDataSource()); + // 扫描Model + sessionFactory.setTypeAliasesPackage("com.example.demo.*.*.entity,com.example.demo.model"); + PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); + // 扫描映射文件 + sessionFactory.setMapperLocations(resolver.getResources("classpath*:mapper/*.xml")); + return sessionFactory; + } + + @Bean + public PlatformTransactionManager transactionManager() { + // 配置事务管理, 使用事务时在方法头部添加@Transactional注解即可 + return new DataSourceTransactionManager(dynamicDataSource()); + } + + @Bean + public PaginationInterceptor paginationInterceptor() { + PaginationInterceptor paginationInterceptor = new PaginationInterceptor(); + + List sqlParserList = new ArrayList<>(); + // 攻击 SQL 阻断解析器、加入解析链 + sqlParserList.add(new BlockAttackSqlParser()); + paginationInterceptor.setSqlParserList(sqlParserList); + return paginationInterceptor; + } +} +*/ diff --git a/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/mapper/OrderMapper.java b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/mapper/OrderMapper.java new file mode 100644 index 0000000..2e01b58 --- /dev/null +++ b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/mapper/OrderMapper.java @@ -0,0 +1,27 @@ +package com.example.demo.mapper; + + +import com.example.demo.model.Order; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +@Mapper +public interface OrderMapper { + + List getOrderByUserId(Long userId); + + List getOrderByOrderId( @Param("orderId") Long orderId); + + List getOrderByUserIdAndOrderId(@Param("userId") Long userId, @Param("orderId") Long orderId); + + List getOrderByRemark(String remark); + + int addOrder(Order order); + + int addOrderEncryptor(Order order); + + void batchInsertOrder(List params); + +} diff --git a/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/mapper/SysDictMapper.java b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/mapper/SysDictMapper.java new file mode 100644 index 0000000..6c41a25 --- /dev/null +++ b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/mapper/SysDictMapper.java @@ -0,0 +1,12 @@ +package com.example.demo.mapper; + +import com.example.demo.model.SysDict; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface SysDictMapper { + + SysDict getDictByCode(String dataCode); + + int addDict(SysDict sysDict); +} diff --git a/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/model/Order.java b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/model/Order.java new file mode 100644 index 0000000..cdf08da --- /dev/null +++ b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/model/Order.java @@ -0,0 +1,29 @@ +package com.example.demo.model; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +@Data +@ApiModel +public class Order implements Serializable { + + + private static final long serialVersionUID = 9009670891546120887L; + + @ApiModelProperty(value = "ID") + private Long id; + + @ApiModelProperty(value = "用户Id") + private Long userId; + + private Long orderId; + + private String remark; + + private Date createTime; + +} diff --git a/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/model/OrderMapper.java b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/model/OrderMapper.java new file mode 100644 index 0000000..5373288 --- /dev/null +++ b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/model/OrderMapper.java @@ -0,0 +1,26 @@ +package com.example.demo.model; + + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +@Mapper +public interface OrderMapper { + + List getOrderByUserId(Long userId); + + List getOrderByOrderId( @Param("orderId") Long orderId); + + List getOrderByUserIdAndOrderId(@Param("userId") Long userId, @Param("orderId") Long orderId); + + List getOrderByRemark(String remark); + + int addOrder(Order order); + + int addOrderEncryptor(Order order); + + void batchInsertOrder(List params); + +} diff --git a/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/model/SysDict.java b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/model/SysDict.java new file mode 100644 index 0000000..d1fac4d --- /dev/null +++ b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/model/SysDict.java @@ -0,0 +1,20 @@ +package com.example.demo.model; + +import lombok.Data; + +import java.util.Date; + + +@Data +public class SysDict { + + private Long id; + + private String dataType; + + private String dataCode; + + private String dataValue; + + private Date createTime; +} diff --git a/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/service/impl/UserService.java b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/service/impl/UserService.java new file mode 100644 index 0000000..6808da2 --- /dev/null +++ b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/service/impl/UserService.java @@ -0,0 +1,21 @@ +package com.example.demo.service.impl; + +import com.example.demo.mapper.SysDictMapper; +import com.example.demo.model.SysDict; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.ArrayList; + +@Component +public class UserService { + + @Resource + private SysDictMapper sysDictMapper; + + public String login(){ + + SysDict s = sysDictMapper.getDictByCode("1"); + return s.toString(); + } +} diff --git a/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/utils/BaseUserDTO.java b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/utils/BaseUserDTO.java new file mode 100644 index 0000000..85dd713 --- /dev/null +++ b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/utils/BaseUserDTO.java @@ -0,0 +1,22 @@ +package com.example.demo.utils; + +import lombok.Data; + +import java.util.List; + +@Data +public class BaseUserDTO { + + String userNmae; + + String userPermission; + + Integer id; + + List permissions; + + public void addPeemission(String p) { + this.permissions.add(p); + } + +} diff --git a/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/utils/CustomUtil.java b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/utils/CustomUtil.java new file mode 100644 index 0000000..e0e35e8 --- /dev/null +++ b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/utils/CustomUtil.java @@ -0,0 +1,228 @@ +package com.example.demo.utils; + +import javax.servlet.http.HttpServletRequest; +import java.math.BigDecimal; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.UUID; +import java.util.regex.Pattern; + +/** + * 自定义工具类 + * + * @author 李嘉 + * @version 1.0 + * @Description 自定义工具类 + * @date 2019/1/8 17:50 + */ +public class CustomUtil { + + /** + * 生成ID,默认小写并且去掉横杆 + * + * @return + */ + public static String GenerateID() { + return GenerateID(false); + } + + /** + * 生成空的字符串。32位0字符串 + * + * @return + */ + public static String GenerateNullID() { + String result = ""; + // 保留num的位数 + // 0 代表前面补充0 + // num 代表长度为4 + // d 代表参数为正数型 + result = String.format("%032d", 0); + + return result; + } + + /** + * 生成ID,默认小写 + * + * @param isHorizontaLine 是否需要横线 + * @return + */ + public static String GenerateID(Boolean isHorizontaLine) { + String tmpId = ""; + if (isHorizontaLine) { + tmpId = UUID.randomUUID().toString(); + } else { + tmpId = UUID.randomUUID().toString().replaceAll("-", ""); + } + return tmpId; + } + + /** + * 生成ID + * + * @param isHorizontaLine 是否需要横线 + * @param isUpper 是否需要大写 + * @return + */ + public static String GenerateID(Boolean isHorizontaLine, Boolean isUpper) { + String tmpId = ""; + if (isHorizontaLine) { + tmpId = UUID.randomUUID().toString(); + } else { + tmpId = GenerateID(false); + } + if (isUpper) { + tmpId = tmpId.toUpperCase(); + } + return tmpId; + } + + /** + * 获取用户真实IP地址,不使用request.getRemoteAddr()的原因是有可能用户使用了代理软件方式避免真实IP地址, + * 可是,如果通过了多级反向代理的话,X-Forwarded-For的值并不止一个,而是一串IP值 + * + * @return ip + */ + public static String GetIPAddress(HttpServletRequest request) { + String ip = request.getHeader("x-forwarded-for"); + System.out.println("x-forwarded-for ip: " + ip); + if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) { + // 多次反向代理后会有多个ip值,第一个ip才是真实ip + if (ip.indexOf(",") != -1) { + ip = ip.split(",")[0]; + } + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("Proxy-Client-IP"); + System.out.println("Proxy-Client-IP ip: " + ip); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("WL-Proxy-Client-IP"); + System.out.println("WL-Proxy-Client-IP ip: " + ip); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_CLIENT_IP"); + System.out.println("HTTP_CLIENT_IP ip: " + ip); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_X_FORWARDED_FOR"); + System.out.println("HTTP_X_FORWARDED_FOR ip: " + ip); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("X-Real-IP"); + System.out.println("X-Real-IP ip: " + ip); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getRemoteAddr(); + System.out.println("getRemoteAddr ip: " + ip); + } + System.out.println("获取客户端ip: " + ip); + return ip; + } + + /** + * 获取真实IP地址 + * + * @param request + * @return + */ + public static String GetIPAddressByInetAddress(HttpServletRequest request) { + String ipAddress = null; + try { + ipAddress = request.getHeader("x-forwarded-for"); + if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) { + ipAddress = request.getHeader("Proxy-Client-IP"); + } + if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) { + ipAddress = request.getHeader("WL-Proxy-Client-IP"); + } + if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) { + ipAddress = request.getRemoteAddr(); + if (ipAddress.equals("127.0.0.1")) { + // 根据网卡取本机配置的IP + InetAddress inet = null; + try { + inet = InetAddress.getLocalHost(); + } catch (UnknownHostException e) { + e.printStackTrace(); + } + ipAddress = inet.getHostAddress(); + } + } + // 对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割 + if (ipAddress != null && ipAddress.length() > 15) { // "***.***.***.***".length() + // = 15 + if (ipAddress.indexOf(",") > 0) { + ipAddress = ipAddress.substring(0, ipAddress.indexOf(",")); + } + } + } catch (Exception e) { + ipAddress = ""; + } + // ipAddress = this.getRequest().getRemoteAddr(); + + return ipAddress; + } + + + /** + * 不够位数的在前面补0,保留num的长度位数字 + * + * @param code + * @return + */ + public static String AutoGenericCode(String code, int num) { + String result = ""; + // 保留num的位数 + // 0 代表前面补充0 + // num 代表长度为4 + // d 代表参数为正数型 + result = String.format("%0" + num + "d", Integer.parseInt(code) + 1); + + return result; + } + + /** + * 字节大小转KB + * + * @param size 字节大小 + * @return + */ + public static double SizeBToKB(long size) { + if (size <= 0) return 0; + return new BigDecimal(size / 1024).setScale(2, BigDecimal.ROUND_DOWN).doubleValue(); + } + + /** + * 去掉多余的0 + * + * @param tmp + * @return + */ + public static String trimLeftZero(String tmp) { + return tmp.replaceAll("^(0+)", ""); + } + + /** + * decimal的值比较 + * + * @param comparativeValue 比较的值,比如数据库取中的值 + * @param beginComparativeValue 被比较的值, 如0、1、2之类的 + * @return + */ + public static Integer decimalCompare(BigDecimal comparativeValue, BigDecimal beginComparativeValue) { + Integer result = comparativeValue.compareTo(beginComparativeValue); + return result; + } + + /** + * 是否是小数 + * + * @param str + * @return + */ + public static boolean isDecimal(String str) { + return Pattern.compile("^[+-]?(0|([1-9]\\d*))(\\.\\d+)?$").matcher(str).find(); + } +} diff --git a/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/utils/DateUtil.java b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/utils/DateUtil.java new file mode 100644 index 0000000..dc83f6c --- /dev/null +++ b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/utils/DateUtil.java @@ -0,0 +1,993 @@ +/* +package com.example.demo.utils; + +import org.joda.time.DateTime; +import org.joda.time.DateTimeZone; +import org.joda.time.Days; +import org.joda.time.LocalDate; +import org.joda.time.format.DateTimeFormat; +import org.joda.time.format.DateTimeFormatter; + +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; + +*/ +/** + * 日期工具 + *//* + +public class DateUtil { + + public static final long ONE_HOUR_TIME_LONG = 3600000; + + */ +/** + * 年(yyyy) + *//* + + public static final String YEAR = "yyyy"; + + */ +/** + * 年-月(yyyy-MM) + *//* + + public static final String YEAR_MONTH = "yyyy-MM"; + + */ +/** + * 年-月-日(yyyy-MM-dd) + *//* + + public static final String YEAR_MONTH_DAY = "yyyy-MM-dd"; + + */ +/** + * 年月日(yyyyMMdd) + *//* + + public static final String YEAR_MONTH_DAY_SIMPLE = "yyyyMMdd"; + + */ +/** + * 年-月-日 小时(yyyy-MM-dd HH) + *//* + + public static final String YEAR_MONTH_DAY_HOUR = "yyyy-MM-dd HH"; + + */ +/** + * 年-月-日 小时(yyyy-MM-dd HH)中文输出 + *//* + + public static final String YEAR_MONTH_DAY_HOUR_CN = "yyyy年MM月dd日HH时"; + + */ +/** + * 年-月-日 小时:分钟(yyyy-MM-dd HH:mm) + *//* + + public static final String YEAR_MONTH_DAY_HOUR_MINUTE = "yyyy-MM-dd HH:mm"; + + */ +/** + * 年-月-日 小时:分钟:秒钟(yyyy-MM-dd HH:mm:ss) + *//* + + public static final String YEAR_MONTH_DAY_HOUR_MINUTE_SECOND = "yyyy-MM-dd HH:mm:ss"; + + */ +/** + * 年月日小时分钟秒钟(yyyyMMddHHmmss) + *//* + + public static final String YEAR_MONTH_DAY_HOUR_MINUTE_SECOND_SIMPLE = "yyyyMMddHHmmss"; + + */ +/** + * 小时:分钟:秒钟(HH:mm:ss) + *//* + + public static final String HOUR_MINUTE_SECOND = "HH:mm:ss"; + + */ +/** + * 小时:分钟(HH:mm) + *//* + + public static final String HOUR_MINUTE = "HH:mm"; + + */ +/** + * 月.日(M.d) + *//* + + public static final String MONTH_DAY = "M.d"; + public static final String REG_EXP_DATE = "^((([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29))\\s+([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$"; + */ +/** + * 一天的秒数 + *//* + + private static final int DAY_SECOND = 24 * 60 * 60; + */ +/** + * 一小时的秒数 + *//* + + private static final int HOUR_SECOND = 60 * 60; + */ +/** + * 一分钟的秒数 + *//* + + private static final int MINUTE_SECOND = 60; + + public DateUtil() { + System.setProperty("user.timezone", "Asia/Shanghai"); + } + + */ +/** + * 获取当前时间 + * + * @return 返回当前时间 + *//* + + public static Date getCurrent() { + return new Date(); + } + + */ +/** + * 获取当前时间并格式化 + * + * @return 返回当前时间 + *//* + + public static String getCurrentDate(String format) { + Date d = new Date(); + SimpleDateFormat sdf = new SimpleDateFormat(format); + return sdf.format(d); + } + + */ +/** + * 获取下个月时间并格式化 + * + * @return 返回当前时间 + *//* + + public static String getNextDate(String format) { + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.MONTH, 1); + SimpleDateFormat dft = new SimpleDateFormat(format); + String preMonth = dft.format(cal.getTime()); + return preMonth; + } + + */ +/** + * 格式化日期时间 + * + * @param date Date对象 + * @param pattern 模式 + * @return 格式化后的日期时间字符串 + *//* + + public static String format(Date date, String pattern) { + if (date == null) + return ""; + return new DateTime(date).toString(pattern); + } + + */ +/** + * 格式化日期时间字符串 + * + * @param dateString 日期时间字符串 + * @param pattern 模式 + * @return Date对象 + *//* + + public static Date formatDateString(String dateString, String pattern) { + try { + DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(pattern); + return dateTimeFormatter.parseDateTime(dateString).toDate(); + } catch (Exception e) { + return null; + } + } + + */ +/** + * 根据秒数获得x天x小时x分钟x秒字符串 + * + * @param second 秒数 + * @return x天x小时x分钟x秒字符串 + *//* + + public static String getDayHourMinuteSecond(int second) { + if (second == 0) { + return "0秒"; + } + StringBuilder sb = new StringBuilder(); + int days = second / DAY_SECOND; + if (days > 0) { + sb.append(days); + sb.append("天"); + second -= days * DAY_SECOND; + } + + int hours = second / HOUR_SECOND; + if (hours > 0) { + sb.append(hours); + sb.append("小时"); + second -= hours * HOUR_SECOND; + } + + int minutes = second / MINUTE_SECOND; + if (minutes > 0) { + sb.append(minutes); + sb.append("分钟"); + second -= minutes * MINUTE_SECOND; + } + if (second > 0) { + sb.append(second); + sb.append("秒"); + } + return sb.toString(); + } + + */ +/** + * 根据秒数获得x天x小时x分钟字符串 + * + * @param second 秒数 + * @return x天x小时x分钟字符串 + *//* + + public static String getDayHourMinute(int second) { + if (second == 0) { + return "0分钟"; + } + StringBuilder sb = new StringBuilder(); + int days = second / DAY_SECOND; + if (days > 0) { + sb.append(days); + sb.append("天"); + second -= days * DAY_SECOND; + } + + int hours = second / HOUR_SECOND; + if (hours > 0) { + sb.append(hours); + sb.append("小时"); + second -= hours * HOUR_SECOND; + } + int minutes = second / MINUTE_SECOND; + if (minutes > 0) { + sb.append(minutes); + sb.append("分钟"); + } + return sb.toString(); + } + + */ +/** + * 获取只含有年月日的DateTime对象 + * + * @param dateTime DateTime对象 + * @return 只含有年月日的DateTime对象 + *//* + + public static DateTime getDateOnly(DateTime dateTime) { + return new DateTime(dateTime.toString(YEAR_MONTH_DAY)); + } + + */ +/** + * 获取当前周的周一和下周一 + * + * @return 日期数组(索引0为周一,索引1为下周一) + *//* + + public static Date[] getMondayAndNextMonday() { + DateTime dateTime = getDateOnly(new DateTime()); + DateTime monday = dateTime.dayOfWeek().withMinimumValue(); + DateTime nextMonday = monday.plusDays(7); + return new Date[]{monday.toDate(), nextMonday.toDate()}; + } + + */ +/** + * 获取指定时间的周一和周日 + * + * @param dateTime DateTime对象 + * @return 日期数组(索引0为周一,索引1为周日) + *//* + + public static Date[] getMondayAndSunday(DateTime dateTime) { + dateTime = getDateOnly(dateTime); + DateTime monday = dateTime.dayOfWeek().withMinimumValue(); + DateTime sunday = monday.plusDays(6); + return new Date[]{monday.toDate(), sunday.toDate()}; + } + + */ +/** + * 和当前时间相比的天数差(正数为大于天数,负数为小于天数,零为同一天) + * + * @param date Date对象 + * @return 和当前时间相比的天数差 + *//* + + public static int compareDaysWithNow(Date date) { + return Days.daysBetween(new DateTime(), new DateTime(date)).getDays(); + } + + */ +/** + * 和今天相比的天数差(正数为大于天数,负数为小于天数,零为同一天) + * + * @param date Date对象 + * @return 和今天相比的天数差 + *//* + + public static int compareDaysWithToday(Date date) { + DateTime today = new DateTime(); + today = new DateTime(today.getYear(), today.getMonthOfYear(), today.getDayOfMonth(), 0, 0, 0, 0); + DateTime compareDay = new DateTime(date); + compareDay = new DateTime(compareDay.getYear(), compareDay.getMonthOfYear(), compareDay.getDayOfMonth(), 0, 0, 0, 0); + return Days.daysBetween(today, compareDay).getDays(); + } + + */ +/** + * 比较时间a到时间b的天数差 + * + * @param a 时间a + * @param b 时间b + * @return 相差天数 + *//* + + public static int compareDaysWithDay(Date a, Date b) { + DateTime today = new DateTime(b); + today = new DateTime(today.getYear(), today.getMonthOfYear(), today.getDayOfMonth(), 0, 0, 0, 0); + DateTime compareDay = new DateTime(a); + compareDay = new DateTime(compareDay.getYear(), compareDay.getMonthOfYear(), compareDay.getDayOfMonth(), 0, 0, 0, 0); + return Days.daysBetween(today, compareDay).getDays(); + } + + */ +/** + * 比较两个时间是否相等(省略毫秒) + * + * @param date Date对象 + * @param compareDate 比较Date对象 + * @return 是否相等 + *//* + + public static boolean compareDateIgnoreMillisecond(Date date, Date compareDate) { + if (date == null && compareDate == null) { + return true; + } else if (date == null && compareDate != null) { + return false; + } else if (date != null && compareDate == null) { + return false; + } + + return (date.getTime() / 1000 == compareDate.getTime() / 1000); + } + + */ +/** + * 根据秒数获取天数 + * + * @param second 秒数 + * @return 天数 + *//* + + public static int getDay(int second) { + return second / DAY_SECOND; + } + + */ +/** + * 获取和今天相比的日期字符串 + * + * @param date Date对象 + * @return 和今天相比的日期字符串 + *//* + + public static String getCompareWithTodayDateString(Date date) { + int days = Math.abs(DateUtil.compareDaysWithToday(date)); + String dateString = ""; + if (days == 0) { + dateString = "今天"; + } else if (days == 1) { + dateString = "昨天"; + } else if (days == 2) { + dateString = "2天前"; + } else if (days == 3) { + dateString = "3天前"; + } else if (days == 4) { + dateString = "4天前"; + } else if (days == 5) { + dateString = "5天前"; + } else if (days == 6) { + dateString = "6天前"; + } else if (days > 6 && days <= 14) { + dateString = "1周前"; + } else if (days > 14 && days <= 21) { + dateString = "2周前"; + } else if (days > 21 && days <= 30) { + dateString = "3周前"; + } else if (days > 30) { + dateString = "1月前"; + } else if (days > 365) { + dateString = "1年前"; + } else if (days > 365 * 3) { + dateString = "3年前"; + } + return dateString; + } + + */ +/** + * 比较两个时间相差分钟数 + * + * @param now 当前时间 + * @param compareDate 比较时间 + * @return 相差分钟数 + *//* + + public static int compareMinutes(Date now, Date compareDate) { + return (int) (now.getTime() - compareDate.getTime()) / 60000; + } + + */ +/** + * 比较时间是本月的第几天 + * + * @param date + * @return + *//* + + public static int getDayOfMonth(Date date) { + DateTime dateTime = new DateTime(date); + return dateTime.getDayOfMonth(); + } + + */ +/** + * 计算当月有几天 + * + * @param date + * @return + *//* + + public static int getDateOfMonth(Date date) { + DateTime dateTime = new DateTime(date); + return dateTime.dayOfMonth().getMaximumValue(); + } + + */ +/** + * 指定时间,判断该时间到现在时间的年数 + * + * @param date 指定时间 + * @return 到现在时间的年数 + *//* + + public static int compareYear(Date date) { + DateTime btd = new DateTime(date); + DateTime nowDate = new DateTime(); + int year = 0; + if (nowDate.getMonthOfYear() > btd.getMonthOfYear()) { + year = nowDate.getYear() - btd.getYear(); + } else if (nowDate.getMonthOfYear() < btd.getMonthOfYear()) { + year = nowDate.getYear() - btd.getYear() - 1; + } else if (nowDate.getMonthOfYear() == btd.getMonthOfYear()) { + if (nowDate.getDayOfMonth() >= btd.getDayOfMonth()) { + year = nowDate.getYear() - btd.getYear(); + } else { + year = nowDate.getYear() - btd.getYear() - 1; + } + } + return year; + } + + */ +/** + * 判断2个时间的时间差 返回字符串形式 + * + * @param date 要对比的字符串 + * @param date2 要对比的字符串 + * @return 字符串形式 如1小时 ,2天2小时 + *//* + + public static String compareDaysWithDate(Date date, Date date2) { + StringBuilder msg = new StringBuilder(); + int minutes = (int) Math.abs((date.getTime() - date2.getTime()) / 60000); + if (minutes / 60 > 0 && minutes / 60 / 24 <= 0) { + msg.append(minutes / 60 + "小时"); + } + if (minutes / 60 / 24 > 0) { + msg.append(minutes / 60 / 24 + "天"); + msg.append(minutes / 60 % 24 + "小时"); + } + return msg.toString(); + } + + */ +/** + * 自动解析多种格式的时间字符串为时间对象
+ * 支持格式为:yyyy-MM-dd HH:mm:ss 支持多种分隔符,以及多种日期精度。 如yyyy年MM月。 HH时mm分ss秒 + * + * @param dateString 时间字符串
+ * @return 格式正确则返回对应的java.util.Date对象 格式错误返回null + *//* + + public static Date formatUnknownString2Date(String dateString) { + try { + if (StringUtil.isEmpty(dateString)) { + return null; + } + dateString = dateString.replace("T", " "); + String hms = "00:00:00"; + dateString = dateString.trim(); + if (dateString.contains(" ")) { + // 截取时分秒 + hms = dateString.substring(dateString.indexOf(" ") + 1); + // 重置日期 + dateString = dateString.substring(0, dateString.indexOf(" ")); + // 多中分隔符的支持 + hms = hms.replace(":", ":"); + hms = hms.replace("时", ":"); + hms = hms.replace("分", ":"); + hms = hms.replace("秒", ":"); + hms = hms.replace("-", ":"); + hms = hms.replace("-", ":"); + // 时间不同精确度的支持 + if (hms.endsWith(":")) { + hms = hms.substring(0, hms.length() - 1); + } + if (hms.split(":").length == 1) { + hms += ":00:00"; + } + if (hms.split(":").length == 2) { + hms += ":00"; + } + } + String[] hmsarr = hms.split(":"); + // 不同日期分隔符的支持 + dateString = dateString.replace(".", "-"); + dateString = dateString.replace("/", "-"); + dateString = dateString.replace("-", "-"); + dateString = dateString.replace("年", "-"); + dateString = dateString.replace("月", "-"); + dateString = dateString.replace("日", ""); + // 切割年月日 + String yearStr, monthStr, dateStr; + // 截取日期 + String[] ymd = dateString.split("-"); + // 判断日期精确度 + yearStr = ymd[0]; + monthStr = ymd.length > 1 ? ymd[1] : ""; + dateStr = ymd.length > 2 ? ymd[2] : ""; + monthStr = monthStr == "" ? Integer.toString(1) : monthStr; + dateStr = dateStr == "" ? Integer.toString(1) : dateStr; + String dtr = (yearStr + "-" + monthStr + "-" + dateStr + " " + hms); + if (!dtr.matches(REG_EXP_DATE)) + return null; + // 返回日期 + return new DateTime(Integer.parseInt(yearStr.trim()), Integer.parseInt(monthStr.trim()), Integer.parseInt(dateStr.trim()), Integer.parseInt(hmsarr[0].trim()), Integer.parseInt(hmsarr[1].trim()), Integer.parseInt(hmsarr[2].trim()), 0).toDate(); + } catch (Exception e) { + return null; + } + } + + */ +/** + * 解析多个时间,指定时间之间的分隔符和时间的格式符 分隔符不能与格式符相同 + * + * @param dateString 传入一个时间段字符串 + * @param spaceChar 指定格式符 + * @param splitChar 指定分隔符 + * @return 格式正确返回分割后的时间对象数组 格式错误返回null
+ * 指定了格式符为. 分隔符为- 返回值为 时间长度为2的Date类型数组
+ * 时间转换的方式详见 {@link DateTimeUtils#formatUnknownString2Date(String dateString)} + *//* + + public static Date[] formatDatesByString(String dateString, String spaceChar, String splitChar) { + if (spaceChar.equals(splitChar)) { + return null; + } + String[] dateStrs = dateString.split(splitChar); + Date[] dates = new Date[dateStrs.length]; + for (int i = 0, size = dateStrs.length; i < size; i++) { + dates[i] = formatUnknownString2Date(dateStrs[i]); + } + return dates; + } + + */ +/** + * 身份证号转生日 + * + * @param identityCard 身份证 + * @return 生日 + *//* + + public static Date identityCard2Date(String identityCard) { + try { + String dateStr; + if (identityCard.length() == 18) { + dateStr = identityCard.substring(6, 14);// 截取18位身份证身份证中生日部分 + return formatDateString(dateStr, "yyyyMMdd"); + } + if (identityCard.length() == 15) { + dateStr = identityCard.substring(6, 12);// 截取15位身份证中生日部分 + return formatDateString(dateStr, "yyMMdd"); + } + return null; + } catch (Exception e) { + return null; + } + } + + public static boolean validDate(String str) { + try { + Date date = formatUnknownString2Date(str); + return date != null; + } catch (Exception e) { + return false; + } + } + + */ +/** + * 根据周数,获取开始日期、结束日期 + * + * @param week 周期 0本周,-1上周,-2上上周,1下周,2下下周 + * @return 返回date[0]开始日期、date[1]结束日期 + *//* + + public static Date[] getWeekStartAndEnd(int week) { + DateTime dateTime = new DateTime(); + LocalDate date = new LocalDate(dateTime.plusWeeks(week)); + + date = date.dayOfWeek().withMinimumValue(); + Date beginDate = date.toDate(); + Date endDate = date.plusDays(6).toDate(); + return new Date[]{beginDate, endDate}; + } + + */ +/** + * 对日期的【秒】进行加/减 + * + * @param date 日期 + * @param seconds 秒数,负数为减 + * @return 加/减几秒后的日期 + *//* + + public static Date addDateSeconds(Date date, int seconds) { + DateTime dateTime = new DateTime(date); + return dateTime.plusSeconds(seconds).toDate(); + } + + */ +/** + * 对日期的【分钟】进行加/减 + * + * @param date 日期 + * @param minutes 分钟数,负数为减 + * @return 加/减几分钟后的日期 + *//* + + public static Date addDateMinutes(Date date, int minutes) { + DateTime dateTime = new DateTime(date); + return dateTime.plusMinutes(minutes).toDate(); + } + + */ +/** + * 对日期的【小时】进行加/减 + * + * @param date 日期 + * @param hours 小时数,负数为减 + * @return 加/减几小时后的日期 + *//* + + public static Date addDateHours(Date date, int hours) { + DateTime dateTime = new DateTime(date); + return dateTime.plusHours(hours).toDate(); + } + + */ +/** + * 对日期的【天】进行加/减 + * + * @param date 日期 + * @param days 天数,负数为减 + * @return 加/减几天后的日期 + *//* + + public static Date addDateDays(Date date, int days) { + DateTime dateTime = new DateTime(date); + return dateTime.plusDays(days).toDate(); + } + + */ +/** + * 对日期的【周】进行加/减 + * + * @param date 日期 + * @param weeks 周数,负数为减 + * @return 加/减几周后的日期 + *//* + + public static Date addDateWeeks(Date date, int weeks) { + DateTime dateTime = new DateTime(date); + return dateTime.plusWeeks(weeks).toDate(); + } + + */ +/** + * 对日期的【月】进行加/减 + * + * @param date 日期 + * @param months 月数,负数为减 + * @return 加/减几月后的日期 + *//* + + public static Date addDateMonths(Date date, int months) { + DateTime dateTime = new DateTime(date); + return dateTime.plusMonths(months).toDate(); + } + + */ +/** + * 对日期的【年】进行加/减 + * + * @param date 日期 + * @param years 年数,负数为减 + * @return 加/减几年后的日期 + *//* + + public static Date addDateYears(Date date, int years) { + DateTime dateTime = new DateTime(date); + return dateTime.plusYears(years).toDate(); + } + + public static String toString(Date date, String format) { + String dateStr = null; + try { + SimpleDateFormat sdf = new SimpleDateFormat(format); + dateStr = sdf.format(date); + } catch (Exception e) { + } + return dateStr; + } + + public static Date parseDate(String dateStr, String format) { + Date date = null; + try { + SimpleDateFormat sdf = new SimpleDateFormat(format); + date = sdf.parse(dateStr); + } catch (Exception e) { + } + return date; + } + + */ +/** + * 获取日期当天的最小时间日期,0点 + *//* + + public static Date getMinTimeDateByDate(Date date) { + if (date == null) + return null; + String datestr = toString(date, "yyyyMMdd"); + return parseDate(datestr, "yyyyMMdd"); + } + + */ +/** + * 获取日期当天的最大时间日期,12点整 + *//* + + public static Date getMaxTimeDateByDate(Date date) { + if (date == null) + return null; + String datestr = toString(date, "yyyyMMdd"); + Date d = parseDate(datestr, "yyyyMMdd"); + return new Date(d.getTime() + 24L * 60L * 60L * 1000L - 1L); + } + + public static long subTime(Date startDate, Date endDate) { + return endDate.getTime() - startDate.getTime(); + } + + */ +/** + * 获取上月第一天最早时间 + * + * @return Date + *//* + + public static Date getLastMonthFirstDay() { + Calendar cal_1 = Calendar.getInstance();// 获取当前日期 + cal_1.setTime(getMinTimeDateByDate(new Date())); + cal_1.add(Calendar.MONTH, -1); + cal_1.set(Calendar.DAY_OF_MONTH, 1); + return cal_1.getTime(); + } + + */ +/** + * 获取上月最后一天最晚时间 + * + * @return Date + *//* + + public static Date getLastMonthLastDay() { + Calendar cale = Calendar.getInstance(); + cale.setTime(getMinTimeDateByDate(new Date())); + cale.add(Calendar.MONTH, -1); + cale.set(Calendar.DAY_OF_MONTH, cale.getActualMaximum(Calendar.DAY_OF_MONTH)); + return new Date(cale.getTime().getTime() + 1000L * 60L * 60L * 24L - 1L); + } + + */ +/** + * 获取本月第一天最早时间 + * + * @return Date + *//* + + public static Date getNowMonthFirstDay() { + Calendar cal_1 = Calendar.getInstance();// 获取当前日期 + cal_1.setTime(getMinTimeDateByDate(new Date())); + cal_1.add(Calendar.MONTH, 0); + cal_1.set(Calendar.DAY_OF_MONTH, 1); + return cal_1.getTime(); + } + + */ +/** + * 获取本月最后一天最晚时间 + * + * @return Date + *//* + + public static Date getNowMonthLastDay() { + Calendar cale = Calendar.getInstance(); + cale.setTime(getMinTimeDateByDate(new Date())); + cale.set(Calendar.DAY_OF_MONTH, cale.getActualMaximum(Calendar.DAY_OF_MONTH)); + return new Date(cale.getTime().getTime() + 1000L * 60L * 60L * 24L - 1L); + } + + */ +/** + * 获取本月最后一天 + * + * @return Date + *//* + + public static Date getTheMonthLastDay(Date date) { + if (date == null) { + return null; + } + Calendar cale = Calendar.getInstance(); + cale.setTime(date); + cale.set(Calendar.DAY_OF_MONTH, cale.getActualMaximum(Calendar.DAY_OF_MONTH)); + cale.set(Calendar.HOUR, 0); + cale.set(Calendar.HOUR_OF_DAY, 0); + cale.set(Calendar.MINUTE, 0); + cale.set(Calendar.SECOND, 0); + cale.set(Calendar.MILLISECOND, 0); + return cale.getTime(); + } + + */ +/** + * 获取格式化的时间,默认是yyyy-MM-dd HH:mm:ss此格式 + * + * @return + *//* + + public static String GetFormatTime() { + DateTime dateTime = new DateTime().withZone(DateTimeZone.forID("Asia/Shanghai")).toLocalDateTime().toDateTime(); + try { + return dateTime.toString("yyyy-MM-dd HH:mm:ss"); + } catch (Exception ex) { + ex.printStackTrace(); + return dateTime.toString(); + } + } + + */ +/** + * 获取格式化的时间 + * + * @param formatter 时间格式化字符串 + * @return + *//* + + public static String GetFormatTime(String formatter) { + DateTime dateTime = new DateTime().withZone(DateTimeZone.forID("Asia/Shanghai")).toLocalDateTime().toDateTime(); + try { + return dateTime.toString(formatter); + } catch (Exception ex) { + ex.printStackTrace(); + return dateTime.toString("yyyy-MM-dd HH:mm:ss"); + } + } + + */ +/** + * 获取格式化的时间字符串 + * + * @param formatTime 自定义时间 + * @param formatter 格式化规则 + * @return + *//* + + public static String GetFormatTime(Date formatTime, String formatter) { + SimpleDateFormat sdf = new SimpleDateFormat(formatter); + try { + return sdf.format(formatTime); + } catch (Exception ex) { + return GetFormatTime(formatter); + } + } + + */ +/** + * 短时间变长时间 + * + * @param tmp 格式:20190301 + * @return + *//* + + public static String sortTimeToLongTime(String tmp) { + return tmp.substring(0, 4) + "-" + tmp.substring(4, 6) + "-" + tmp.substring(6, 8); + } + + */ +/** + * 判断时间是否符合对比度 + * + * @param month 要比对的月份 + * @param limitMonth 要获取当前时间的前几个月或后几个月的偏移量 + * @param days 要对比的天数 + * @return 返回结果,0、不做任何操作,1、月份和天数都在可操作范围,2、月份在可操作范围 + *//* + + */ +/*public static Integer compares(String month, Integer limitMonth, Integer days) { + if (StringUtil.isEmpty(month)) { + return 0; + } + RemindDateUtils remindDateUtils = new RemindDateUtils(); + String limitMonths = GetFormatTime(remindDateUtils.getBeforeMonth(limitMonth), "MM"); + String day = GetFormatTime("dd"); + if (Integer.parseInt(month) >= Integer.parseInt(limitMonths)) { + if (Integer.parseInt(month) == Integer.parseInt(limitMonths)) { + if (Integer.parseInt(day) <= days) { + return 1; + } + } else if (Integer.parseInt(month) > Integer.parseInt(limitMonths)) { + return 2; + } + } + return 0; + }*//* + + +} +*/ diff --git a/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/utils/MyGenerate.java b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/utils/MyGenerate.java new file mode 100644 index 0000000..03c768d --- /dev/null +++ b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/utils/MyGenerate.java @@ -0,0 +1,103 @@ +/* +package com.example.demo.utils; + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.core.toolkit.StringPool; +import com.baomidou.mybatisplus.generator.AutoGenerator; +import com.baomidou.mybatisplus.generator.InjectionConfig; +import com.baomidou.mybatisplus.generator.config.*; +import com.baomidou.mybatisplus.generator.config.po.TableInfo; +import com.baomidou.mybatisplus.generator.config.rules.DateType; +import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; +import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine; + +import java.util.ArrayList; +import java.util.List; + +*/ +/** + * 生成工具 + * + * @author lijia + * @version 1.0 + * @Description 生成工具 + * @date 2020/1/8 14:25 星期三 + *//* + +public class MyGenerate { + + */ +/** + * RUN THIS + *//* + + public static void main(String[] args) { + // 代码生成器 + AutoGenerator mpg = new AutoGenerator(); + + // 全局配置/Users/lijia/code/java/V2019/sdpc/sdpc-gateway + GlobalConfig gc = new GlobalConfig(); + String projectPath = System.getProperty("user.dir"); + gc.setOutputDir("/Users/lijia/IdeaProjects/demo/src/main/java"); + gc.setAuthor("Lij"); + gc.setOpen(false); + gc.setSwagger2(false); + gc.setActiveRecord(true); + gc.setIdType(IdType.ID_WORKER_STR); + gc.setFileOverride(true); + gc.setDateType(DateType.ONLY_DATE); + mpg.setGlobalConfig(gc); + + // 数据源配置 + DataSourceConfig dsc = new DataSourceConfig(); + dsc.setDbType(DbType.MYSQL); + dsc.setUrl("jdbc:mysql://127.0.0.1:3306/test?serverTimezone=Asia/Shanghai&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull"); + dsc.setDriverName("com.mysql.cj.jdbc.Driver"); + dsc.setUsername("root"); + dsc.setPassword("spring"); + mpg.setDataSource(dsc); + + // 包配置 + PackageConfig pc = new PackageConfig(); + pc.setParent("com.example.demo"); + pc.setMapper("dao"); + pc.setEntity("model"); + mpg.setPackageInfo(pc); + + // 自定义配置 + InjectionConfig cfg = new InjectionConfig() { + @Override + public void initMap() { + // to do nothing + } + }; + List focList = new ArrayList<>(); + focList.add(new FileOutConfig("/templates/mapper.xml.ftl") { + @Override + public String outputFile(TableInfo tableInfo) { + // 自定义输入文件名称 + return "/Users/lijia/IdeaProjects/demo/src/main/resources/mapper/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML; + } + }); + cfg.setFileOutConfigList(focList); + mpg.setCfg(cfg); + mpg.setTemplate(new TemplateConfig().setXml(null)); + + // 策略配置 + StrategyConfig strategy = new StrategyConfig(); + strategy.setCapitalMode(false); + strategy.setNaming(NamingStrategy.underline_to_camel); + strategy.setColumnNaming(NamingStrategy.underline_to_camel); + strategy.setEntityLombokModel(true); + strategy.setInclude("people_config"); + // TODO 数据库Id为大写时,此时填写小写id,如果数据库为小写id,此时填写大写Id + strategy.setSuperEntityColumns("id"); +// strategy.setLogicDeleteFieldName("Status"); + mpg.setStrategy(strategy); + // 选择 freemarker 引擎需要指定如下加,注意 pom 依赖必须有! + mpg.setTemplateEngine(new FreemarkerTemplateEngine()); + mpg.execute(); + } +} +*/ diff --git a/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/utils/ResultEnum.java b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/utils/ResultEnum.java new file mode 100644 index 0000000..9c01a08 --- /dev/null +++ b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/utils/ResultEnum.java @@ -0,0 +1,113 @@ +package com.example.demo.utils; + +/** + * 返回结果枚举 + * + * @author 李嘉 + * @version 1.0 + * @Description 返回结果枚举 + * @date 2019/1/8 15:24 + */ +public enum ResultEnum { + + /** + * 无操作 + */ + None("无操作", 0), + + /** + * 成功 + */ + Success("成功", 10200), + + /** + * 失败 + */ + Fail("失败", 10300), + + /** + * 错误请求 + */ + ErrorRequest("错误请求", 10400), + + /** + * 未授权 + */ + NoAuthorization("未授权", 10401), + + /** + * 拒绝请求 + */ + RefuseRequest("拒绝请求", 10403), + + /** + * 未找到 + */ + NotFound("未找到", 10404), + + /** + * 参数不符合 + */ + NotParameter("参数不符合", 10406), + + /** + * 请求超时 + */ + RequestTimeOut("请求超时", 10408), + + /** + * 登录超时 + */ + LoginTimeOut("登录超时", 10409), + + /** + * 服务器错误 + */ + Error("服务器错误", 10500), + + /** + * http协议错误 + */ + ErrorHttp("http协议错误", 10505), + + /** + * 业务问题 + */ + Business("业务问题", 10400); + + private String name; + private int index; + + ResultEnum() { + } + + ResultEnum(String name, int index) { + this.name = name; + this.index = index; + } + + public static String getName(int index) { + for (ResultEnum info : ResultEnum.values()) { + if (info.getIndex() == index) { + return info.getName(); + } + } + return null; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } +} diff --git a/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/utils/SpringContextUtils.java b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/utils/SpringContextUtils.java new file mode 100644 index 0000000..5dd0b12 --- /dev/null +++ b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/utils/SpringContextUtils.java @@ -0,0 +1,92 @@ +package com.example.demo.utils; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.DisposableBean; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; + +/** + * Spring上下文获取工具 + * + * @author 李嘉 + * @version 1.0 + * @Description Spring上下文获取工具 + * @date 2019-05-10 13:25 + */ +@Component +public class SpringContextUtils implements ApplicationContextAware, DisposableBean { + + public static ApplicationContext applicationContext; + + /** + * 取得存储在静态变量中的ApplicationContext. + */ + public static ApplicationContext getApplicationContext() { + checkApplicationContext(); + return applicationContext; + } + + /** + * 实现ApplicationContextAware接口的context注入函数, 将其存入静态变量. + */ + @Override + public void setApplicationContext(ApplicationContext applicationContext) + throws BeansException { + SpringContextUtils.applicationContext = applicationContext; + } + + /** + * 从静态变量ApplicationContext中取得Bean, 自动转型为所赋值对象的类型. + */ + @SuppressWarnings("unchecked") + public static T getBean(String name) { + checkApplicationContext(); + return (T) applicationContext.getBean(name); + } + + /** + * 从静态变量ApplicationContext中取得Bean, 自动转型为所赋值对象的类型. + */ + public static T getBean(Class clazz) { + checkApplicationContext(); + return applicationContext.getBean(clazz); + } + + public static T getBean(String name, Class requiredType) { + return applicationContext.getBean(name, requiredType); + } + + public static boolean containsBean(String name) { + return applicationContext.containsBean(name); + } + + public static boolean isSingleton(String name) { + return applicationContext.isSingleton(name); + } + + public static Class getType(String name) { + return applicationContext.getType(name); + } + + + /** + * 清除applicationContext静态变量. + */ + public static void cleanApplicationContext() { + applicationContext = null; + } + + private static void checkApplicationContext() { + if (applicationContext == null) { + throw new IllegalStateException("applicaitonContext未注入,请在applicationContext.xml中定义SpringContextHolder"); + } + } + + @Override + public void destroy() throws Exception { + SpringContextUtils.cleanApplicationContext(); + } +} diff --git a/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/utils/StringUtil.java b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/utils/StringUtil.java new file mode 100644 index 0000000..f3b3a67 --- /dev/null +++ b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/utils/StringUtil.java @@ -0,0 +1,198 @@ +/* +package com.example.demo.utils; + +import java.text.DecimalFormat; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.List; + +*/ +/** + * 字符串工具类 + * + * @author: lixuanli + * @date: 2018/4/16 13:27 + *//* + +public class StringUtil { + + */ +/** + * 获取两字符串的相似度 + * + * @param str 需要比对字符串 + * @param target 比对目标字符串 + *//* + + public static float getSimilarityRatio(String str, String target) { + return 1 - (float) compare(str, target) / Math.max(str.length(), target.length()); + + } + + */ +/** + * 生成对应模块单据名称 + * + * @param customerName 客户名称 + * @param moduleName 模块名称 + * @param dateFormat 日期格式 + * @return 单据名称 + * @author: lixuanli + * @date: 2018/5/9 09:52 + *//* + + public static String getTitleByModule(String customerName, String moduleName, String dateFormat) { + String currentDate = DateUtil.getCurrentDate(dateFormat); + return customerName + "_" + moduleName + "_" + currentDate; + } + + */ +/** + * 生成对应模块单号 + * + * @param number 单号序列 + * @param numberFormat 单号格式 + * @param moduleShortName 模块简称 + * @param customerAreaShortName 客户地区简称 + * @param dateFormat 日期格式 + * @return + * @author: lixuanli + * @date: 2018/5/9 10:02 + *//* + + public static String getNumberByMOdule(int number, String numberFormat, String moduleShortName, String customerAreaShortName, String dateFormat) { + NumberFormat nf = new DecimalFormat(numberFormat); + String sNumber = nf.format(number); + String currentYear = DateUtil.getCurrentDate(dateFormat); + return moduleShortName + "-" + customerAreaShortName + "-" + currentYear + "-" + sNumber; + } + + */ +/** + * 方法描述 : 生成下个月对应模块单号 + * + * @param number 单号序列 + * @param numberFormat 单号格式 + * @param moduleShortName 模块简称 + * @param customerAreaShortName 客户地区简称 + * @param dateFormat 日期格式 + * @return + * @author fangxs + * @date 2018年7月23日 + *//* + + public static String getNextMonNumberByMOdule(int number, String numberFormat, String moduleShortName, String customerAreaShortName, String dateFormat) { + NumberFormat nf = new DecimalFormat(numberFormat); + String sNumber = nf.format(number); + String currentYear = DateUtil.getNextDate(dateFormat); + return moduleShortName + "-" + customerAreaShortName + "-" + currentYear + "-" + sNumber; + } + + private static int compare(String str, String target) { + int[][] d; // 矩阵 + int n = str.length(); + int m = target.length(); + int i; // 遍历str的 + int j; // 遍历target的 + char ch1; // str的 + char ch2; // target的 + int temp; // 记录相同字符,在某个矩阵位置值的增量,不是0就是1 + + if (n == 0) { + return m; + } + + if (m == 0) { + return n; + } + + d = new int[n + 1][m + 1]; + + // 初始化第一列 + for (i = 0; i <= n; i++) { + d[i][0] = i; + } + // 初始化第一行 + for (j = 0; j <= m; j++) { + d[0][j] = j; + } + // 遍历str + for (i = 1; i <= n; i++) { + ch1 = str.charAt(i - 1); + // 去匹配target + for (j = 1; j <= m; j++) { + ch2 = target.charAt(j - 1); + if (ch1 == ch2) { + temp = 0; + } else { + temp = 1; + } + + // 左边+1,上边+1, 左上角+temp取最小 + d[i][j] = min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + temp); + } + } + return d[n][m]; + } + + private static int min(int one, int two, int three) { + return (one = one < two ? one : two) < three ? one : three; + } + + */ +/** + * String 字符串转 List集合 + * + * @param tmp + * @param splitStr 切割字符串 + * @return + *//* + + public static List stringToList(String tmp, String splitStr) { + List listObj = new ArrayList<>(); + String[] ids = tmp.split(splitStr); + for (Integer i = 0; i < ids.length; i++) { + if (!isEmpty(ids[0])) { + listObj.add(ids[i]); + } + } + return listObj; + } + + */ +/** + * 是否为空字符串(包含"null") + * + * @param str + * @return + *//* + + public static boolean isEmpty(Object str) { + return str == null || "".equals(str) || "null".equals(str); + } + + */ +/** + * 获取字符串值 + * + * @param str + * @return + *//* + + public static String getValue(Object str) { + return isEmpty(str) ? "" : String.valueOf(str); + } + + */ +/** + * 判断两个字符结果是否相同 + * + * @param str1 + * @param str2 + * @return + *//* + + public static boolean equales(Object str1, Object str2) { + return getValue(str1).equals(str2); + } +}*/ diff --git a/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/utils/UserContext.java b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/utils/UserContext.java new file mode 100644 index 0000000..a8affda --- /dev/null +++ b/SpringBoot-DynamicDataSource/src/main/java/com/example/demo/utils/UserContext.java @@ -0,0 +1,34 @@ +package com.example.demo.utils; + + + +public class UserContext { + private static final ThreadLocal user = new ThreadLocal<>(); + + private UserContext() { + } + + public static Integer getUserId() throws Exception { + BaseUserDTO baseUserDTO = getUser(); + return baseUserDTO.getId(); + } + + public static BaseUserDTO getUser() throws Exception { + BaseUserDTO baseUser = user.get(); + if (null == baseUser) { + throw new Exception("登录失效,请重新登录!"); + } + return baseUser; + } + + + + public static void setBaseUser(BaseUserDTO baseUser) { + user.set(baseUser); + } + + public static void remove() { + user.remove(); + } + +} \ No newline at end of file diff --git a/SpringBoot-DynamicDataSource/src/main/resources/application.yaml b/SpringBoot-DynamicDataSource/src/main/resources/application.yaml new file mode 100644 index 0000000..ac95d22 --- /dev/null +++ b/SpringBoot-DynamicDataSource/src/main/resources/application.yaml @@ -0,0 +1,54 @@ + +server: + servlet: + application-display-name: springBoot-aop + port: 19086 + + # 主配置 +spring: + # 数据源配置 + datasource: + # 修改数据源为druid + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.cj.jdbc.Driver #这个要根据mysql-connector-java版本 + # druid配置 + druid: + # 主数据源 + master: + driver-class-name: com.mysql.jdbc.Driver + # 默认数据库连接(配置库) + url: jdbc:mysql://localhost:3306/db_00?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: share + password: hta@123 + # 递增db配置 + db1: + driver-class-name: com.mysql.jdbc.Driver #这个要根据mysql-connector-java版本 + url: jdbc:mysql://localhost:3306/db_01?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: share + password: hta@123 + initial-size: 5 # 初始化时建立物理连接的个数 + max-active: 30 # 最大连接池数量 + min-idle: 5 # 最小连接池数量 + max-wait: 60000 # 获取连接时最大等待时间,单位毫秒 + time-between-eviction-runs-millis: 60000 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 + min-evictable-idle-time-millis: 300000 # 连接保持空闲而不被驱逐的最小时间 + validation-query: SELECT 1 FROM DUAL # 用来检测连接是否有效的sql,要求是一个查询语句 + test-while-idle: true # 建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。 + test-on-borrow: false # 申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。 + test-on-return: false # 归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。 + pool-prepared-statements: true # 是否缓存preparedStatement,也就是PSCache。PSCache对支持游标的数据库性能提升巨大,比如说oracle。在mysql下建议关闭。 + max-pool-prepared-statement-per-connection-size: 50 # 要启用PSCache,必须配置大于0,当大于0时,poolPreparedStatements自动触发修改为true。 + filters: stat,wall,log4j2 # 配置监控统计拦截的filters,去掉后监控界面sql无法统计;配置监控统计拦截的filters,stat:监控统计、log4j:日志记录、wall:防御sql注入 + connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500 # 通过connectProperties属性来打开mergeSql功能;慢SQL记录 + use-global-data-source-stat: true # 合并多个DruidDataSource的监控数据 + stat-view-servlet: + allow: '' # IP白名单(没有配置或者为空,则允许所有访问) allow: 127.0.0.1,192.168.163.1 + deny: '' # IP黑名单 (存在共同时,deny优先于allow) + login-password: xxxxxx # 登录密码 + login-username: admin # 登录名 + reset-enable: false # 禁用HTML页面上的“Reset All”功能 + url-pattern: /druid/* # 配置DruidStatViewServlet + web-stat-filter: # 配置DruidStatFilter + enabled: true + exclusions: '*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*' + url-pattern: /* diff --git a/SpringBoot-DynamicDataSource/src/main/resources/mapper/DictMapper.xml b/SpringBoot-DynamicDataSource/src/main/resources/mapper/DictMapper.xml new file mode 100644 index 0000000..8dbbd8b --- /dev/null +++ b/SpringBoot-DynamicDataSource/src/main/resources/mapper/DictMapper.xml @@ -0,0 +1,28 @@ + + + + + + + + + insert into sys_dict( + data_type,data_code,data_value,create_time + ) + values + ( + #{dataType}, + #{dataCode}, + #{dataValue}, + now() + ) + + \ No newline at end of file diff --git a/SpringBoot-DynamicDataSource/src/main/resources/mapper/OrderMapper.xml b/SpringBoot-DynamicDataSource/src/main/resources/mapper/OrderMapper.xml new file mode 100644 index 0000000..a01be2c --- /dev/null +++ b/SpringBoot-DynamicDataSource/src/main/resources/mapper/OrderMapper.xml @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + insert into t_order( + user_id, + order_id, + remark, + create_time + ) + values + ( + #{userId}, + #{orderId}, + #{remark}, + now() + ) + + + + + insert into t_order( + user_id, + order_id, + create_time + ) + values + ( + #{userId}, + #{orderId}, + now() + ) + + + + + insert into t_order( + user_id, + order_id, + remark, + create_time + ) + values + + ( + #{item.userId,jdbcType=BIGINT}, + #{item.orderId,jdbcType=BIGINT}, + #{item.remark,jdbcType=VARCHAR}, + now() + ) + + + + + + \ No newline at end of file diff --git a/SpringBoot-DynamicDataSource/src/test/java/com/example/demo/DemoApplicationTests.java b/SpringBoot-DynamicDataSource/src/test/java/com/example/demo/DemoApplicationTests.java new file mode 100644 index 0000000..eaa9969 --- /dev/null +++ b/SpringBoot-DynamicDataSource/src/test/java/com/example/demo/DemoApplicationTests.java @@ -0,0 +1,13 @@ +package com.example.demo; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class DemoApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/SpringBoot-DynamicDataSource/target/classes/application.yaml b/SpringBoot-DynamicDataSource/target/classes/application.yaml new file mode 100644 index 0000000..ac95d22 --- /dev/null +++ b/SpringBoot-DynamicDataSource/target/classes/application.yaml @@ -0,0 +1,54 @@ + +server: + servlet: + application-display-name: springBoot-aop + port: 19086 + + # 主配置 +spring: + # 数据源配置 + datasource: + # 修改数据源为druid + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.cj.jdbc.Driver #这个要根据mysql-connector-java版本 + # druid配置 + druid: + # 主数据源 + master: + driver-class-name: com.mysql.jdbc.Driver + # 默认数据库连接(配置库) + url: jdbc:mysql://localhost:3306/db_00?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: share + password: hta@123 + # 递增db配置 + db1: + driver-class-name: com.mysql.jdbc.Driver #这个要根据mysql-connector-java版本 + url: jdbc:mysql://localhost:3306/db_01?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: share + password: hta@123 + initial-size: 5 # 初始化时建立物理连接的个数 + max-active: 30 # 最大连接池数量 + min-idle: 5 # 最小连接池数量 + max-wait: 60000 # 获取连接时最大等待时间,单位毫秒 + time-between-eviction-runs-millis: 60000 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 + min-evictable-idle-time-millis: 300000 # 连接保持空闲而不被驱逐的最小时间 + validation-query: SELECT 1 FROM DUAL # 用来检测连接是否有效的sql,要求是一个查询语句 + test-while-idle: true # 建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。 + test-on-borrow: false # 申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。 + test-on-return: false # 归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。 + pool-prepared-statements: true # 是否缓存preparedStatement,也就是PSCache。PSCache对支持游标的数据库性能提升巨大,比如说oracle。在mysql下建议关闭。 + max-pool-prepared-statement-per-connection-size: 50 # 要启用PSCache,必须配置大于0,当大于0时,poolPreparedStatements自动触发修改为true。 + filters: stat,wall,log4j2 # 配置监控统计拦截的filters,去掉后监控界面sql无法统计;配置监控统计拦截的filters,stat:监控统计、log4j:日志记录、wall:防御sql注入 + connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500 # 通过connectProperties属性来打开mergeSql功能;慢SQL记录 + use-global-data-source-stat: true # 合并多个DruidDataSource的监控数据 + stat-view-servlet: + allow: '' # IP白名单(没有配置或者为空,则允许所有访问) allow: 127.0.0.1,192.168.163.1 + deny: '' # IP黑名单 (存在共同时,deny优先于allow) + login-password: xxxxxx # 登录密码 + login-username: admin # 登录名 + reset-enable: false # 禁用HTML页面上的“Reset All”功能 + url-pattern: /druid/* # 配置DruidStatViewServlet + web-stat-filter: # 配置DruidStatFilter + enabled: true + exclusions: '*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*' + url-pattern: /* diff --git a/SpringBoot-DynamicDataSource/target/classes/com/example/demo/DemoApplication.class b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/DemoApplication.class new file mode 100644 index 0000000..cfa8003 Binary files /dev/null and b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/DemoApplication.class differ diff --git a/SpringBoot-DynamicDataSource/target/classes/com/example/demo/controller/DemoController.class b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/controller/DemoController.class new file mode 100644 index 0000000..9871c5f Binary files /dev/null and b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/controller/DemoController.class differ diff --git a/SpringBoot-DynamicDataSource/target/classes/com/example/demo/datasource/DataSourceConfig.class b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/datasource/DataSourceConfig.class new file mode 100644 index 0000000..297779f Binary files /dev/null and b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/datasource/DataSourceConfig.class differ diff --git a/SpringBoot-DynamicDataSource/target/classes/com/example/demo/datasource/DataSourceConstant.class b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/datasource/DataSourceConstant.class new file mode 100644 index 0000000..4f61159 Binary files /dev/null and b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/datasource/DataSourceConstant.class differ diff --git a/SpringBoot-DynamicDataSource/target/classes/com/example/demo/datasource/DynamicDataSource.class b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/datasource/DynamicDataSource.class new file mode 100644 index 0000000..1424336 Binary files /dev/null and b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/datasource/DynamicDataSource.class differ diff --git a/SpringBoot-DynamicDataSource/target/classes/com/example/demo/datasource/DynamicDataSourceAspect.class b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/datasource/DynamicDataSourceAspect.class new file mode 100644 index 0000000..74d9a66 Binary files /dev/null and b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/datasource/DynamicDataSourceAspect.class differ diff --git a/SpringBoot-DynamicDataSource/target/classes/com/example/demo/datasource/DynamicDataSourceContextHolder$1.class b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/datasource/DynamicDataSourceContextHolder$1.class new file mode 100644 index 0000000..29f03fa Binary files /dev/null and b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/datasource/DynamicDataSourceContextHolder$1.class differ diff --git a/SpringBoot-DynamicDataSource/target/classes/com/example/demo/datasource/DynamicDataSourceContextHolder.class b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/datasource/DynamicDataSourceContextHolder.class new file mode 100644 index 0000000..e1a813c Binary files /dev/null and b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/datasource/DynamicDataSourceContextHolder.class differ diff --git a/SpringBoot-DynamicDataSource/target/classes/com/example/demo/datasource/MyBatisConfig.class b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/datasource/MyBatisConfig.class new file mode 100644 index 0000000..52c2d3e Binary files /dev/null and b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/datasource/MyBatisConfig.class differ diff --git a/SpringBoot-DynamicDataSource/target/classes/com/example/demo/mapper/OrderMapper.class b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/mapper/OrderMapper.class new file mode 100644 index 0000000..5a6b807 Binary files /dev/null and b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/mapper/OrderMapper.class differ diff --git a/SpringBoot-DynamicDataSource/target/classes/com/example/demo/mapper/SysDictMapper.class b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/mapper/SysDictMapper.class new file mode 100644 index 0000000..f8eacbd Binary files /dev/null and b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/mapper/SysDictMapper.class differ diff --git a/SpringBoot-DynamicDataSource/target/classes/com/example/demo/model/Order.class b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/model/Order.class new file mode 100644 index 0000000..87924e7 Binary files /dev/null and b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/model/Order.class differ diff --git a/SpringBoot-DynamicDataSource/target/classes/com/example/demo/model/OrderMapper.class b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/model/OrderMapper.class new file mode 100644 index 0000000..42df9c8 Binary files /dev/null and b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/model/OrderMapper.class differ diff --git a/SpringBoot-DynamicDataSource/target/classes/com/example/demo/model/SysDict.class b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/model/SysDict.class new file mode 100644 index 0000000..ab8755e Binary files /dev/null and b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/model/SysDict.class differ diff --git a/SpringBoot-DynamicDataSource/target/classes/com/example/demo/service/impl/UserService.class b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/service/impl/UserService.class new file mode 100644 index 0000000..6f890a3 Binary files /dev/null and b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/service/impl/UserService.class differ diff --git a/SpringBoot-DynamicDataSource/target/classes/com/example/demo/utils/BaseUserDTO.class b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/utils/BaseUserDTO.class new file mode 100644 index 0000000..6f5320e Binary files /dev/null and b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/utils/BaseUserDTO.class differ diff --git a/SpringBoot-DynamicDataSource/target/classes/com/example/demo/utils/CustomUtil.class b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/utils/CustomUtil.class new file mode 100644 index 0000000..32c263f Binary files /dev/null and b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/utils/CustomUtil.class differ diff --git a/SpringBoot-DynamicDataSource/target/classes/com/example/demo/utils/ResultEnum.class b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/utils/ResultEnum.class new file mode 100644 index 0000000..a35d251 Binary files /dev/null and b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/utils/ResultEnum.class differ diff --git a/SpringBoot-DynamicDataSource/target/classes/com/example/demo/utils/SpringContextUtils.class b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/utils/SpringContextUtils.class new file mode 100644 index 0000000..50fde74 Binary files /dev/null and b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/utils/SpringContextUtils.class differ diff --git a/SpringBoot-DynamicDataSource/target/classes/com/example/demo/utils/UserContext.class b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/utils/UserContext.class new file mode 100644 index 0000000..a547a51 Binary files /dev/null and b/SpringBoot-DynamicDataSource/target/classes/com/example/demo/utils/UserContext.class differ diff --git a/SpringBoot-DynamicDataSource/target/classes/mapper/DictMapper.xml b/SpringBoot-DynamicDataSource/target/classes/mapper/DictMapper.xml new file mode 100644 index 0000000..8dbbd8b --- /dev/null +++ b/SpringBoot-DynamicDataSource/target/classes/mapper/DictMapper.xml @@ -0,0 +1,28 @@ + + + + + + + + + insert into sys_dict( + data_type,data_code,data_value,create_time + ) + values + ( + #{dataType}, + #{dataCode}, + #{dataValue}, + now() + ) + + \ No newline at end of file diff --git a/SpringBoot-DynamicDataSource/target/classes/mapper/OrderMapper.xml b/SpringBoot-DynamicDataSource/target/classes/mapper/OrderMapper.xml new file mode 100644 index 0000000..a01be2c --- /dev/null +++ b/SpringBoot-DynamicDataSource/target/classes/mapper/OrderMapper.xml @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + insert into t_order( + user_id, + order_id, + remark, + create_time + ) + values + ( + #{userId}, + #{orderId}, + #{remark}, + now() + ) + + + + + insert into t_order( + user_id, + order_id, + create_time + ) + values + ( + #{userId}, + #{orderId}, + now() + ) + + + + + insert into t_order( + user_id, + order_id, + remark, + create_time + ) + values + + ( + #{item.userId,jdbcType=BIGINT}, + #{item.orderId,jdbcType=BIGINT}, + #{item.remark,jdbcType=VARCHAR}, + now() + ) + + + + + + \ No newline at end of file diff --git a/SpringBoot-DynamicDataSource/target/test-classes/com/example/demo/DemoApplicationTests.class b/SpringBoot-DynamicDataSource/target/test-classes/com/example/demo/DemoApplicationTests.class new file mode 100644 index 0000000..27b8e18 Binary files /dev/null and b/SpringBoot-DynamicDataSource/target/test-classes/com/example/demo/DemoApplicationTests.class differ diff --git a/SpringBoot-LTS/src/test/java/com/fancv/AppTest.java b/SpringBoot-LTS/src/test/java/com/fancv/AppTest.java new file mode 100644 index 0000000..84d0c0b --- /dev/null +++ b/SpringBoot-LTS/src/test/java/com/fancv/AppTest.java @@ -0,0 +1,20 @@ +package com.fancv; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +/** + * Unit test for simple App. + */ +public class AppTest +{ + /** + * Rigorous Test :-) + */ + @Test + public void shouldAnswerWithTrue() + { + assertTrue( true ); + } +} diff --git a/SpringBoot-MyBatis-Advances/Readme.md b/SpringBoot-MyBatis-Advances/Readme.md index 27dd9b3..5a4d729 100644 --- a/SpringBoot-MyBatis-Advances/Readme.md +++ b/SpringBoot-MyBatis-Advances/Readme.md @@ -1,3 +1,5 @@ # springboot mybatis advance demo ## DataSource drui ## Reading and writing separation +## spring cache redis +spring cache redis 类型的实现,满足常用的配置、数据字典、类目等常见缓存场景的使用。 diff --git a/SpringBoot-MyBatis-Advances/pom.xml b/SpringBoot-MyBatis-Advances/pom.xml index 2e195f3..6a46376 100644 --- a/SpringBoot-MyBatis-Advances/pom.xml +++ b/SpringBoot-MyBatis-Advances/pom.xml @@ -28,5 +28,53 @@ druid-spring-boot-starter 1.1.17 + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 2.1.4 + + + mysql + mysql-connector-java + + + org.apache.maven.doxia + doxia-site-renderer + 1.11.1 + + + org.springframework.boot + spring-boot-starter-cache + + + org.springframework.boot + spring-boot-starter-data-redis + 2.3.9.RELEASE + - \ No newline at end of file + + + + org.mybatis.generator + mybatis-generator-maven-plugin + 1.4.0 + + + ${basedir}/src/main/resources/generator/generatorConfig.xml + true + true + + + + org.apache.maven.plugins + maven-site-plugin + 3.7.1 + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 3.0.0 + + + + diff --git a/SpringBoot-MyBatis-Advances/src/main/java/com/fancv/Application_Mybatis.java b/SpringBoot-MyBatis-Advances/src/main/java/com/fancv/Application_Mybatis.java index 1b8c859..9c2724b 100644 --- a/SpringBoot-MyBatis-Advances/src/main/java/com/fancv/Application_Mybatis.java +++ b/SpringBoot-MyBatis-Advances/src/main/java/com/fancv/Application_Mybatis.java @@ -2,6 +2,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cache.annotation.EnableCaching; import springfox.documentation.swagger2.annotations.EnableSwagger2; //TODO @@ -14,6 +15,7 @@ */ @SpringBootApplication @EnableSwagger2 +@EnableCaching public class Application_Mybatis { public static void main(String[] args) { diff --git a/SpringBoot-MyBatis-Advances/src/main/java/com/fancv/config/RedisCacheConfig.java b/SpringBoot-MyBatis-Advances/src/main/java/com/fancv/config/RedisCacheConfig.java new file mode 100644 index 0000000..0aab800 --- /dev/null +++ b/SpringBoot-MyBatis-Advances/src/main/java/com/fancv/config/RedisCacheConfig.java @@ -0,0 +1,127 @@ +package com.fancv.config; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.cache.CacheManager; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.cache.interceptor.KeyGenerator; +import org.springframework.cache.interceptor.SimpleKeyGenerator; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.cache.RedisCacheConfiguration; +import org.springframework.data.redis.cache.RedisCacheManager; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.RedisSerializationContext; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +import java.time.Duration; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +@Configuration +@EnableCaching +public class RedisCacheConfig { + + @Value("${cache.default.expire-time:2000}") + private int defaultExpireTime; + @Value("${cache.user.expire-time:1000}") + private int userCacheExpireTime; + @Value("${cache.user.name:cache}") + private String userCacheName; + + /* *//** + * Redis缓存管理器 + * + * @param lettuceConnectionFactory + * @return + *//* + @Bean + public CacheManager cacheManager(RedisConnectionFactory lettuceConnectionFactory) { + RedisCacheConfiguration defaultCacheConfig = RedisCacheConfiguration.defaultCacheConfig(); + // 设置缓存管理器管理的缓存的默认过期时间 + defaultCacheConfig = defaultCacheConfig.entryTtl(Duration.ofSeconds(defaultExpireTime)) + // 设置 key为string序列化 + .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer())) + // 设置value为json序列化 + .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer())) + // 不缓存空值 + .disableCachingNullValues(); + + Set cacheNames = new HashSet<>(); + cacheNames.add(userCacheName); + + // 对每个缓存空间应用不同的配置 + Map configMap = new HashMap<>(); + configMap.put(userCacheName, defaultCacheConfig.entryTtl(Duration.ofSeconds(userCacheExpireTime))); + configMap.put("users", defaultCacheConfig.entryTtl(Duration.ofSeconds(400))); + + RedisCacheManager cacheManager = RedisCacheManager.builder(lettuceConnectionFactory) + .cacheDefaults(defaultCacheConfig) + .initialCacheNames(cacheNames) + .withInitialCacheConfigurations(configMap) + .build(); + return cacheManager; + }*/ + + + /* * + * 缓存管理器 + * + * @param lettuceConnectionFactory + * @return*/ + + @Bean + public CacheManager cacheManager(RedisConnectionFactory lettuceConnectionFactory) { + RedisCacheConfiguration defaultCacheConfig = RedisCacheConfiguration.defaultCacheConfig(); + // 设置缓存管理器管理的缓存的默认过期时间 + defaultCacheConfig = defaultCacheConfig.entryTtl(Duration.ofSeconds(defaultExpireTime)) + // 设置 key为string序列化 + .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer())) + // 设置value为json序列化 + .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer())) + // 不缓存空值 + .disableCachingNullValues(); + + Set cacheNames = new HashSet<>(); + cacheNames.add(userCacheName); + + // 对每个缓存空间应用不同的配置 + Map configMap = new HashMap<>(); + configMap.put(userCacheName, defaultCacheConfig.entryTtl(Duration.ofSeconds(userCacheExpireTime))); + configMap.put("users", defaultCacheConfig.entryTtl(Duration.ofSeconds(400))); + + RedisCacheManager cacheManager = RedisCacheManager.builder(lettuceConnectionFactory) + .cacheDefaults(defaultCacheConfig) + .initialCacheNames(cacheNames) + .withInitialCacheConfigurations(configMap) + .build(); + return cacheManager; + } + /** + * 自定义缓存的redis的KeyGenerator【key生成策略】 + * 注意: 该方法只是声明了key的生成策略,需在@Cacheable注解中通过keyGenerator属性指定具体的key生成策略 + * 可以根据业务情况,配置多个生成策略 + * 如: @Cacheable(value = "key", keyGenerator = "cacheKeyGenerator") + */ + @Bean + public KeyGenerator keyGenerator() { + /** + * target: 类 + * method: 方法 + * params: 方法参数 + */ + return (target, method, params) -> { + //获取代理对象的最终目标对象 + StringBuilder sb = new StringBuilder(); + sb.append(target.getClass().getSimpleName()).append(":"); + sb.append(method.getName()).append(":"); + //调用SimpleKey的key生成器 + Object key = SimpleKeyGenerator.generateKey(params); + return sb.append(key); + }; + } + + +} diff --git a/SpringBoot-MyBatis-Advances/src/main/java/com/fancv/controller/DemoController.java b/SpringBoot-MyBatis-Advances/src/main/java/com/fancv/controller/DemoController.java new file mode 100644 index 0000000..bdaf868 --- /dev/null +++ b/SpringBoot-MyBatis-Advances/src/main/java/com/fancv/controller/DemoController.java @@ -0,0 +1,64 @@ +package com.fancv.controller; + +import com.fancv.dao.User; +import com.fancv.mapper.MyUserMapper; +import com.fancv.service.UserService; +import io.swagger.annotations.Api; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.accept.MappingMediaTypeFileExtensionResolver; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +@RestController +@RequestMapping("mybatis") +@Api(value = "User") +public class DemoController { + + @Autowired + MyUserMapper userMapper; + + @Autowired + UserService userService; + + + @GetMapping("user_info") + public User getUserInfo(Integer id){ + + User user = userService.getUerInfo(id); + User user1 = userService.getUerInfoWithoutKey(); + return user; + } + + @GetMapping("replace") + public int Replace(){ + List users= new ArrayList<>(); + User a= new User(); + a.setAge(10); + a.setId(3); + a.setEmail("dshkfjh"); + a.setModifyTime(new Date()); + a.setCreateTime(new Date()); + a.setName("dfsd"); + a.setPassword("124321"); + users.add(a); + return userMapper.updateOrInsertClientInfo(users); + } + + @GetMapping("merge") + public int merge(){ + User a= new User(); + a.setAge(10); + a.setId(3); + a.setEmail("dshkfjh"); + a.setModifyTime(new Date()); + a.setCreateTime(new Date()); + a.setName("dfa"); + a.setPassword("124321"); + return 1; + } +} diff --git a/SpringBoot-MyBatis-Advances/src/main/java/com/fancv/controller/DruidStatController.java b/SpringBoot-MyBatis-Advances/src/main/java/com/fancv/controller/DruidStatController.java index 57557ea..f63a81f 100644 --- a/SpringBoot-MyBatis-Advances/src/main/java/com/fancv/controller/DruidStatController.java +++ b/SpringBoot-MyBatis-Advances/src/main/java/com/fancv/controller/DruidStatController.java @@ -8,9 +8,16 @@ @RestController @Api(tags = "druid") public class DruidStatController { + + + @GetMapping("/druid/stat") public Object druidStat() { // DruidStatManagerFacade#getDataSourceStatDataList 该方法可以获取所有数据源的监控数据,除此之外 DruidStatManagerFacade 还提供了一些其他方法,你可以按需选择使用。 return DruidStatManagerFacade.getInstance().getDataSourceStatDataList(); } + + + + } \ No newline at end of file diff --git a/SpringBoot-MyBatis-Advances/src/main/java/com/fancv/dao/User.java b/SpringBoot-MyBatis-Advances/src/main/java/com/fancv/dao/User.java new file mode 100644 index 0000000..d172df0 --- /dev/null +++ b/SpringBoot-MyBatis-Advances/src/main/java/com/fancv/dao/User.java @@ -0,0 +1,93 @@ +package com.fancv.dao; + +import java.io.Serializable; +import java.util.Date; + +public class User implements Serializable { + private Integer id; + + private String name; + + private String password; + + private Integer age; + + private String email; + + private Date createTime; + + private Date modifyTime; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public Integer getAge() { + return age; + } + + public void setAge(Integer age) { + this.age = age; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Date getModifyTime() { + return modifyTime; + } + + public void setModifyTime(Date modifyTime) { + this.modifyTime = modifyTime; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()); + sb.append(" ["); + sb.append("Hash = ").append(hashCode()); + sb.append(", id=").append(id); + sb.append(", name=").append(name); + sb.append(", password=").append(password); + sb.append(", age=").append(age); + sb.append(", email=").append(email); + sb.append(", createTime=").append(createTime); + sb.append(", modifyTime=").append(modifyTime); + sb.append("]"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/SpringBoot-MyBatis-Advances/src/main/java/com/fancv/mapper/MyUserMapper.java b/SpringBoot-MyBatis-Advances/src/main/java/com/fancv/mapper/MyUserMapper.java new file mode 100644 index 0000000..90dde9e --- /dev/null +++ b/SpringBoot-MyBatis-Advances/src/main/java/com/fancv/mapper/MyUserMapper.java @@ -0,0 +1,39 @@ +package com.fancv.mapper; + +import com.fancv.dao.User; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface MyUserMapper { + int deleteByPrimaryKey(Integer id); + + int insert(User record); + + int insertSelective(User record); + + User selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(User record); + + int updateByPrimaryKey(User record); + + /** + * replace 根据主键判断数据是否存在,若不存在则插入。存在则不变。 + * + * 批量更新数据,如果数据库存在则更新,不存在则写入 + * + * 分析唯一建 + * @param users + * @return + */ + int updateOrInsertClientInfo(List users); + + + int updateOrInsertClientInfoTwo(List users); + + int updateOrInsertClientInfoSingle(User user); + + +} \ No newline at end of file diff --git a/SpringBoot-MyBatis-Advances/src/main/java/com/fancv/service/UserService.java b/SpringBoot-MyBatis-Advances/src/main/java/com/fancv/service/UserService.java new file mode 100644 index 0000000..6fc0f57 --- /dev/null +++ b/SpringBoot-MyBatis-Advances/src/main/java/com/fancv/service/UserService.java @@ -0,0 +1,36 @@ +package com.fancv.service; + +import com.fancv.dao.User; +import com.fancv.mapper.MyUserMapper; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheConfig; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.stereotype.Service; + +@Service +@Log4j2 +@EnableCaching +@CacheConfig(cacheNames = "users") +public class UserService { + + @Autowired + MyUserMapper userMapper; + + /** + * @Cacheable(cacheNames = "users", condition = "#id > 0", sync = true, keyGenerator = "keyGenerator",key = "'user-' + #id") + * Both 'key' and 'keyGenerator' attributes have been set. 不能同时使用 + * @param id + * @return + */ + @Cacheable(cacheNames = "users", condition = "#id > 0", sync = true, keyGenerator = "keyGenerator") + public User getUerInfo(Integer id) { + return userMapper.selectByPrimaryKey(id); + } + + @Cacheable(cacheNames = "ca", sync = true, keyGenerator = "keyGenerator") + public User getUerInfoWithoutKey() { + return userMapper.selectByPrimaryKey(2); + } +} diff --git a/SpringBoot-MyBatis-Advances/src/main/resources/application.yaml b/SpringBoot-MyBatis-Advances/src/main/resources/application.yaml index 101859b..9c0dcb4 100644 --- a/SpringBoot-MyBatis-Advances/src/main/resources/application.yaml +++ b/SpringBoot-MyBatis-Advances/src/main/resources/application.yaml @@ -1,9 +1,18 @@ spring: + cache: + redis: + key-prefix: "sp:" + time-to-live: 800 + type: redis + redis: + port: 6379 + host: 127.0.0.1 + database: 10 datasource: username: admin password: hta@123 - url: jdbc:mysql://localhost:3306/mysql8_study?useUnicode=true&characterEncoding=utf-8&useSSL=false - driver-class-name: com.alibaba.druid.proxy.DruidDriver + url: jdbc:mysql://localhost:3306/mysql8_study?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone = GMT&zeroDateTimeBehavior=convertToNull + driver-class-name: com.mysql.cj.jdbc.Driver type: com.alibaba.druid.pool.DruidDataSource # 下面为连接池的补充设置,应用到上面所有数据源中 # 初始化大小,最小,最大 @@ -28,6 +37,15 @@ spring: use-global-data-source-stat: true # 通过connectProperties属性来打开mergeSql功能;慢SQL记录 connect-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 +server: + port: 9091 +mybatis: + mapper-locations: classpath:mappers/*Mapper.xml + type-aliases-package: com.fancv.dao + +logging: + level: + com.fancv.mapper: debug diff --git a/SpringBoot-MyBatis-Advances/src/main/resources/datasource.properties b/SpringBoot-MyBatis-Advances/src/main/resources/datasource.properties new file mode 100644 index 0000000..9c6e651 --- /dev/null +++ b/SpringBoot-MyBatis-Advances/src/main/resources/datasource.properties @@ -0,0 +1,4 @@ +jdbc.driverClass=com.mysql.cj.jdbc.Driver +jdbc.url=jdbc:mysql://localhost:3306/mysql8_study?useUnicode=true&characterEncoding=utf-8&useSSL=false +jdbc.username=admin +jdbc.password=hta@123 diff --git a/SpringBoot-MyBatis-Advances/src/main/resources/generator/generatorConfig.xml b/SpringBoot-MyBatis-Advances/src/main/resources/generator/generatorConfig.xml new file mode 100644 index 0000000..9640c08 --- /dev/null +++ b/SpringBoot-MyBatis-Advances/src/main/resources/generator/generatorConfig.xml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+
diff --git a/SpringBoot-MyBatis-Advances/src/main/resources/mappers/UserMapper.xml b/SpringBoot-MyBatis-Advances/src/main/resources/mappers/UserMapper.xml new file mode 100644 index 0000000..e5d37da --- /dev/null +++ b/SpringBoot-MyBatis-Advances/src/main/resources/mappers/UserMapper.xml @@ -0,0 +1,155 @@ + + + + + + + + + + + + + + id, name, password, age, email, create_time, modify_time + + + name, password, age, email, create_time, modify_time + + + + delete from fancv_user + where id = #{id,jdbcType=INTEGER} + + + insert into fancv_user (id, name, password, + age, email, create_time, + modify_time) + values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, + #{age,jdbcType=INTEGER}, #{email,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, + #{modifyTime,jdbcType=TIMESTAMP}) + + + insert into fancv_user + + + id, + + + name, + + + password, + + + age, + + + email, + + + create_time, + + + modify_time, + + + + + #{id,jdbcType=INTEGER}, + + + #{name,jdbcType=VARCHAR}, + + + #{password,jdbcType=VARCHAR}, + + + #{age,jdbcType=INTEGER}, + + + #{email,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{modifyTime,jdbcType=TIMESTAMP}, + + + + + update fancv_user + + + name = #{name,jdbcType=VARCHAR}, + + + password = #{password,jdbcType=VARCHAR}, + + + age = #{age,jdbcType=INTEGER}, + + + email = #{email,jdbcType=VARCHAR}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + modify_time = #{modifyTime,jdbcType=TIMESTAMP}, + + + where id = #{id,jdbcType=INTEGER} + + + update fancv_user + set name = #{name,jdbcType=VARCHAR}, + password = #{password,jdbcType=VARCHAR}, + age = #{age,jdbcType=INTEGER}, + email = #{email,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + modify_time = #{modifyTime,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=INTEGER} + + + + + replace into fancv_user + () + VALUES + + (#{it.id}, #{it.name},#{it.password},#{it.age}, + #{it.email},#{it.createTime},#{it.modifyTime} + ) + + + + + insert into fancv_user + () + VALUES + + (#{it.id}, #{it.name},#{it.password},#{it.age}, + #{it.email},#{it.createTime},#{it.modifyTime} + ) + on duplicate key update age = VALUES(age) ,email = VALUES(email) + + + + + + + insert into fancv_user (id, name, password, + age, email, create_time, + modify_time) ON DUPLICATE KEY UPDATE age = VALUES(age) ,email = VALUES(email); + + + + + \ No newline at end of file diff --git a/SpringBoot-OSS/lib2/aliyun-openservices-1.2.1.jar b/SpringBoot-OSS/lib2/aliyun-openservices-1.2.1.jar new file mode 100644 index 0000000..5ea7726 Binary files /dev/null and b/SpringBoot-OSS/lib2/aliyun-openservices-1.2.1.jar differ diff --git a/SpringBoot-OSS/lib2/api-top-oss-2.1.multiclient-SNAPSHOT.jar b/SpringBoot-OSS/lib2/api-top-oss-2.1.multiclient-SNAPSHOT.jar new file mode 100644 index 0000000..5b98e28 Binary files /dev/null and b/SpringBoot-OSS/lib2/api-top-oss-2.1.multiclient-SNAPSHOT.jar differ diff --git a/SpringBoot-OSS/lib2/core-2.3.14.jar b/SpringBoot-OSS/lib2/core-2.3.14.jar new file mode 100644 index 0000000..1851ba4 Binary files /dev/null and b/SpringBoot-OSS/lib2/core-2.3.14.jar differ diff --git a/SpringBoot-OSS/lib2/raycloud-sheji-dam-sdk-1.0.0-SNAPSHOT.jar b/SpringBoot-OSS/lib2/raycloud-sheji-dam-sdk-1.0.0-SNAPSHOT.jar new file mode 100644 index 0000000..8e91c84 Binary files /dev/null and b/SpringBoot-OSS/lib2/raycloud-sheji-dam-sdk-1.0.0-SNAPSHOT.jar differ diff --git a/SpringBoot-OSS/lib_v1/SpringBoot-Commons-1.0-SNAPSHOT.jar b/SpringBoot-OSS/lib_v1/SpringBoot-Commons-1.0-SNAPSHOT.jar new file mode 100644 index 0000000..8d33d6d Binary files /dev/null and b/SpringBoot-OSS/lib_v1/SpringBoot-Commons-1.0-SNAPSHOT.jar differ diff --git a/SpringBoot-OSS/lib_v1/raycloud-sheji-dam-sdk-1.0.0-SNAPSHOT.jar b/SpringBoot-OSS/lib_v1/raycloud-sheji-dam-sdk-1.0.0-SNAPSHOT.jar new file mode 100644 index 0000000..b1d2891 Binary files /dev/null and b/SpringBoot-OSS/lib_v1/raycloud-sheji-dam-sdk-1.0.0-SNAPSHOT.jar differ diff --git a/SpringBoot-OSS/pom.xml b/SpringBoot-OSS/pom.xml index 9dcd2e3..7edbd68 100644 --- a/SpringBoot-OSS/pom.xml +++ b/SpringBoot-OSS/pom.xml @@ -49,6 +49,14 @@ jaxb-runtime 2.3.3 + + + + + net.coobird + thumbnailator + 0.4.8 + diff --git a/SpringBoot-OSS/readme.txt b/SpringBoot-OSS/readme.txt new file mode 100644 index 0000000..558cc94 --- /dev/null +++ b/SpringBoot-OSS/readme.txt @@ -0,0 +1,15 @@ +1.dam-sdk 上传图片demo项目 + +2.sdk:计算图片缩略图,组装上传文件信息所需要的参数。 + +3.DAM 对接分为两个部分,接入方将图片通过sdk 上传到阿里oss + +利用 sdk 返回的图片信息 组装 上传接口需要的信息。 + +4. CURL: + +curl --location --request POST 'http://localhost:9010/oss/file' \ +--header 'Content-Type: multipart/form-data' \ +--header 'Cookie: JSESSIONID=C7FEAD76DAFADA0ACAE587E9109E7BBE' \ +--form 'file=@"/C:/Users/hamish/Pictures/fancv/clipboard1.png"' + diff --git a/SpringBoot-OSS/src/main/java/com/fancv/App.java b/SpringBoot-OSS/src/main/java/com/fancv/App.java new file mode 100644 index 0000000..8f534fe --- /dev/null +++ b/SpringBoot-OSS/src/main/java/com/fancv/App.java @@ -0,0 +1,20 @@ +package com.fancv; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +/** + * Hello world! + * + */ +@SpringBootApplication(scanBasePackages ={"com.fancv","com.raycloud.sheji"} ) +@EnableSwagger2 +public class App +{ + public static void main( String[] args ) + { + SpringApplication.run(App.class,args); + System.out.println( "Hello World!" ); + } +} diff --git a/SpringBoot-OSS/src/main/java/com/fancv/config/UserDamOssClientConfig.java b/SpringBoot-OSS/src/main/java/com/fancv/config/UserDamOssClientConfig.java new file mode 100644 index 0000000..ea7c305 --- /dev/null +++ b/SpringBoot-OSS/src/main/java/com/fancv/config/UserDamOssClientConfig.java @@ -0,0 +1,39 @@ +package com.fancv.config; + +import com.raycloud.qnee.commons.api.top.oss.OSSCommonUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +@Configuration +@Component +public class UserDamOssClientConfig { + + @Value("${dam.oss.accessKeyId}") + private String accessKeyId; + @Value("${dam.oss.accessKeySecret}") + private String appKey; + @Value("${dam.oss.bucketName}") + private String bucket; + @Value("${dam.oss.ossEndPoint}") + private String endPoint; + @Value("${dam.oss.ossEndPointInner}") + private String endPointInner; + + public UserDamOssClientConfig() { + } + + @Override + public int hashCode() { + return super.hashCode(); + } + + @Bean(name = "damOpenOssCommonUtils") + @Scope("prototype") + public OSSCommonUtils ossPublicCommonUtils() { + OSSCommonUtils ossCommonUtils= new OSSCommonUtils(this.accessKeyId, this.appKey, this.endPoint, this.endPointInner, this.bucket); + return ossCommonUtils; + } +} diff --git a/SpringBoot-OSS/src/main/java/com/fancv/controller/ossController.java b/SpringBoot-OSS/src/main/java/com/fancv/controller/ossController.java index 787984c..a24d0a8 100644 --- a/SpringBoot-OSS/src/main/java/com/fancv/controller/ossController.java +++ b/SpringBoot-OSS/src/main/java/com/fancv/controller/ossController.java @@ -1,6 +1,7 @@ package com.fancv.controller; import com.fancv.service.OssService; +import com.raycloud.sheji.dto.DamFileUpdateDto; import io.swagger.annotations.Api; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; @@ -22,7 +23,7 @@ public class ossController { OssService ossService; @PostMapping("/file") - public String put(@RequestParam("file") MultipartFile file) throws IOException { + public DamFileUpdateDto put(@RequestParam("file") MultipartFile file) throws Exception { InputStream inputStream = file.getInputStream(); String name = file.getOriginalFilename(); @@ -32,6 +33,6 @@ public String put(@RequestParam("file") MultipartFile file) throws IOException { @PostMapping("/delete") public Boolean put(@RequestParam("key") String key) throws IOException { - return ossService.deleteObject(key); + return ossService.fileExist(key); } } diff --git a/SpringBoot-OSS/src/main/java/com/fancv/service/OssService.java b/SpringBoot-OSS/src/main/java/com/fancv/service/OssService.java index 7a1345d..092fa4a 100644 --- a/SpringBoot-OSS/src/main/java/com/fancv/service/OssService.java +++ b/SpringBoot-OSS/src/main/java/com/fancv/service/OssService.java @@ -1,6 +1,7 @@ package com.fancv.service; -import com.ray.sdk.OssUtil.RayOssUtil; +import com.raycloud.sheji.dto.DamFileUpdateDto; +import com.raycloud.sheji.util.DamOpenOssUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -11,16 +12,21 @@ public class OssService { @Autowired - RayOssUtil rayOssUtil; + DamOpenOssUtils damOpenOssUtils; + public OssService() { + super(); + } + + public DamFileUpdateDto putObject(String name, InputStream inputStream) throws Exception { + + return damOpenOssUtils.uploadFileAndThumbnailToOss("exampledir",name,inputStream,false); - public String putObject(String name, InputStream inputStream) throws IOException { - return rayOssUtil.putObject("exampledir/", "/" + name, inputStream); } - public Boolean deleteObject(String name) throws IOException { + public Boolean fileExist(String name) throws IOException { - return rayOssUtil.deleteObject(name); + return damOpenOssUtils.fileExist(name); } } diff --git a/SpringBoot-OSS/src/main/resources/application.properties b/SpringBoot-OSS/src/main/resources/application.properties index 79971fa..47dc664 100644 --- a/SpringBoot-OSS/src/main/resources/application.properties +++ b/SpringBoot-OSS/src/main/resources/application.properties @@ -1,31 +1,28 @@ spring.application.name=spring-boot-oss - spring.rabbitmq.host=127.0.0.1 spring.rabbitmq.port=5672 spring.rabbitmq.username=guest spring.rabbitmq.password=guest - - -# ߿ confirm ȷϻ +# \u00B7\u00A2\u00CB\u00CD\u00D5\u00DF\u00BF\u00AA\u00C6\u00F4 confirm \u00C8\u00B7\u00C8\u00CF\u00BB\u00FA\u00D6\u00C6 spring.rabbitmq.publisher-confirm-type=simple -# ߿ return ȷϻ +# \u00B7\u00A2\u00CB\u00CD\u00D5\u00DF\u00BF\u00AA\u00C6\u00F4 return \u00C8\u00B7\u00C8\u00CF\u00BB\u00FA\u00D6\u00C6 spring.rabbitmq.publisher-returns=true #################################################### -# Ѷֶ ack +# \u00C9\u00E8\u00D6\u00C3\u00CF\u00FB\u00B7\u00D1\u00B6\u00CB\u00CA\u00D6\u00B6\u00AF ack spring.rabbitmq.listener.simple.acknowledge-mode=manual -# Ƿ֧ +# \u00CA\u00C7\u00B7\u00F1\u00D6\u00A7\u00B3\u00D6\u00D6\u00D8\u00CA\u00D4 spring.rabbitmq.listener.simple.retry.enabled=true - - server.port=9010 - - -rayOssKey=LTAI5tDT2HxdMRBVV8pE1MNv -rayOssSecret=1whvEgrT0t7jo2vJxi0QgmJ0aWnzyH -rayOssEndpoint=https://oss-cn-zhangjiakou.aliyuncs.com -rayBucketName=fancv-sys - +rayOssKey=LTAI5t5sF7sXqD8by7p3RCRB +rayOssSecret= +rayOssEndpoint= +rayBucketName= spring.servlet.multipart.enabled=true spring.servlet.multipart.max-file-size=2048MB spring.servlet.multipart.maxRequestSize=2048MB +dam.oss.accessKeyId= +dam.oss.accessKeySecret= +dam.oss.bucketName= +dam.oss.ossEndPoint=oss-cn-zhangjiakou.aliyuncs.com +dam.oss.ossEndPointInner=oss-cn-zhangjiakou.aliyuncs.com diff --git a/SpringBoot-OSS/src/test/java/com/fancv/AppTest.java b/SpringBoot-OSS/src/test/java/com/fancv/AppTest.java new file mode 100644 index 0000000..84d0c0b --- /dev/null +++ b/SpringBoot-OSS/src/test/java/com/fancv/AppTest.java @@ -0,0 +1,20 @@ +package com.fancv; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +/** + * Unit test for simple App. + */ +public class AppTest +{ + /** + * Rigorous Test :-) + */ + @Test + public void shouldAnswerWithTrue() + { + assertTrue( true ); + } +} diff --git a/SpringBoot-OSS/src/test/java/com/fancv/Demo.java b/SpringBoot-OSS/src/test/java/com/fancv/Demo.java index 587b9e3..8bacba4 100644 --- a/SpringBoot-OSS/src/test/java/com/fancv/Demo.java +++ b/SpringBoot-OSS/src/test/java/com/fancv/Demo.java @@ -20,12 +20,12 @@ public static void main(String[] args) throws Exception { // Endpoint以华东1(杭州)为例,其它Region请按实际情况填写。 String endpoint = "https://oss-cn-zhangjiakou.aliyuncs.com"; // 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。 - String accessKeyId = "LTAI5tDT2HxdMRBVV8pE1MNv"; - String accessKeySecret = "1whvEgrT0t7jo2vJxi0QgmJ0aWnzyH"; + String accessKeyId = "LTAI5t5sF7sXqD8by7p3RCRB"; + String accessKeySecret = "mwTXDxnvGGO6V5YcMzp80q8a5oH67l"; // 填写Bucket名称,例如examplebucket。 String bucketName = "fancv-sys"; // 填写Object完整路径,例如exampledir/exampleobject.txt。Object完整路径中不能包含Bucket名称。 按照orgId 年月日存储文件 - String objectName = "exampledir/5exampleobject.txt"; + String objectName = "exampledir/5.txt"; // 创建OSSClient实例。 OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); diff --git a/SpringBoot-OSS/src/test/java/com/fancv/OssVersionDemo.java b/SpringBoot-OSS/src/test/java/com/fancv/OssVersionDemo.java new file mode 100644 index 0000000..a1d429f --- /dev/null +++ b/SpringBoot-OSS/src/test/java/com/fancv/OssVersionDemo.java @@ -0,0 +1,144 @@ +package com.fancv; + +import com.aliyun.oss.ClientException; +import com.aliyun.oss.OSS; +import com.aliyun.oss.OSSClientBuilder; +import com.aliyun.oss.OSSException; +import com.aliyun.oss.model.*; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.InputStreamReader; + +public class OssVersionDemo { + public static void main(String[] args) throws Exception { + // Endpoint以华东1(杭州)为例,其它Region请按实际情况填写。 + String endpoint = "https://oss-cn-zhangjiakou.aliyuncs.com"; + // 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。 + String accessKeyId = "LTAI5t5sF7sXqD8by7p3RCRB"; + String accessKeySecret = "mwTXDxnvGGO6V5YcMzp80q8a5oH67l"; + // 填写Bucket名称,例如examplebucket。 + String bucketName = "fancv-sys"; + // 填写Object完整路径,例如exampledir/exampleobject.txt。Object完整路径中不能包含Bucket名称。 按照orgId 年月日存储文件 + String objectName = "exampledir/5.txt"; + + // 创建OSSClient实例。 + OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); + + // upload(bucketName, objectName, ossClient); + + allFiles(ossClient,objectName); + } + + private static void upload(String bucketName, String objectName, OSS ossClient) { + try { + // 以上传字符串为例。 + String content = "Hello OSS 5"; + PutObjectResult result = ossClient.putObject(bucketName, objectName, new ByteArrayInputStream(content.getBytes())); + // 查看此次上传Object的VersionId。 + System.out.println("result.versionid: " + result.getVersionId()); + } catch (OSSException oe) { + System.out.println("Caught an OSSException, which means your request made it to OSS, " + + "but was rejected with an error response for some reason."); + System.out.println("Error Message:" + oe.getErrorMessage()); + System.out.println("Error Code:" + oe.getErrorCode()); + System.out.println("Request ID:" + oe.getRequestId()); + System.out.println("Host ID:" + oe.getHostId()); + } catch (ClientException ce) { + System.out.println("Caught an ClientException, which means the client encountered " + + "a serious internal problem while trying to communicate with OSS, " + + "such as not being able to access the network."); + System.out.println("Error Message:" + ce.getMessage()); + } finally { + if (ossClient != null) { + ossClient.shutdown(); + } + } + } + + + + public static void allFiles(OSS ossClient, String objectName){ + String bucketName = "fancv-sys"; + try { + // 列举包括删除标记在内的所有Object的版本信息。 + String nextKeyMarker = null; + String nextVersionMarker = null; + VersionListing versionListing = null; + do { + ListVersionsRequest listVersionsRequest = new ListVersionsRequest() + .withBucketName(bucketName) + .withKeyMarker(nextKeyMarker) + .withVersionIdMarker(nextVersionMarker); + + versionListing = ossClient.listVersions(listVersionsRequest); + for (OSSVersionSummary ossVersion : versionListing.getVersionSummaries()) { + System.out.println("key name: " + ossVersion.getKey()); + System.out.println("versionid: " + ossVersion.getVersionId()); + System.out.println("Is latest: " + ossVersion.isLatest()); + System.out.println("Is delete marker: " + ossVersion.isDeleteMarker()); + } + + nextKeyMarker = versionListing.getNextKeyMarker(); + nextVersionMarker = versionListing.getNextVersionIdMarker(); + } while (versionListing.isTruncated()); + } catch (OSSException oe) { + System.out.println("Caught an OSSException, which means your request made it to OSS, " + + "but was rejected with an error response for some reason."); + System.out.println("Error Message:" + oe.getErrorMessage()); + System.out.println("Error Code:" + oe.getErrorCode()); + System.out.println("Request ID:" + oe.getRequestId()); + System.out.println("Host ID:" + oe.getHostId()); + } catch (ClientException ce) { + System.out.println("Caught an ClientException, which means the client encountered " + + "a serious internal problem while trying to communicate with OSS, " + + "such as not being able to access the network."); + System.out.println("Error Message:" + ce.getMessage()); + } finally { + if (ossClient != null) { + ossClient.shutdown(); + } + } + } + + public static void download(OSS ossClient, String objectName){ + // 填写Bucket名称,例如examplebucket。 + String bucketName = "fancv-sys"; + try { + // 封装GetObject请求。 + GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, objectName); + getObjectRequest.setVersionId("CAEQNxiBgICmp5OcjxgiIGJiOGYxZTNmZWQxNjQ1MDE5NTRmNjRkZDEzY2MyMWEx"); + // ossObject包含文件所在的存储空间名称、文件名称、文件元信息以及一个输入流。 + OSSObject ossObject = ossClient.getObject(getObjectRequest); + + // 查看已下载Object的VersionId。 + System.out.println("Get Object versionid:" + ossObject.getObjectMetadata().getVersionId()); + // 读取指定VersionId的Object内容。 + System.out.println("Object content:"); + BufferedReader reader = new BufferedReader(new InputStreamReader(ossObject.getObjectContent())); + while (true) { + String line = reader.readLine(); + if (line == null) break; + System.out.println("\n" + line); + } + + } catch (OSSException oe) { + System.out.println("Caught an OSSException, which means your request made it to OSS, " + + "but was rejected with an error response for some reason."); + System.out.println("Error Message:" + oe.getErrorMessage()); + System.out.println("Error Code:" + oe.getErrorCode()); + System.out.println("Request ID:" + oe.getRequestId()); + System.out.println("Host ID:" + oe.getHostId()); + } catch (Throwable ce) { + System.out.println("Caught an ClientException, which means the client encountered " + + "a serious internal problem while trying to communicate with OSS, " + + "such as not being able to access the network."); + System.out.println("Error Message:" + ce.getMessage()); + } finally { + // 关闭OSSClient。 + if (ossClient != null) { + ossClient.shutdown(); + } + } + } +} \ No newline at end of file diff --git a/SpringBoot-OSS/target/classes/application.properties b/SpringBoot-OSS/target/classes/application.properties new file mode 100644 index 0000000..d420212 --- /dev/null +++ b/SpringBoot-OSS/target/classes/application.properties @@ -0,0 +1,38 @@ +spring.application.name=spring-boot-oss + +spring.rabbitmq.host=127.0.0.1 +spring.rabbitmq.port=5672 +spring.rabbitmq.username=guest +spring.rabbitmq.password=guest + + +# �����߿��� confirm ȷ�ϻ��� +spring.rabbitmq.publisher-confirm-type=simple +# �����߿��� return ȷ�ϻ��� +spring.rabbitmq.publisher-returns=true +#################################################### +# �������Ѷ��ֶ� ack +spring.rabbitmq.listener.simple.acknowledge-mode=manual +# �Ƿ�֧������ +spring.rabbitmq.listener.simple.retry.enabled=true + + +server.port=9010 + + +rayOssKey=LTAI5t5sF7sXqD8by7p3RCRB +rayOssSecret=mwTXDxnvGGO6V5YcMzp80q8a5oH67l +rayOssEndpoint=https://oss-cn-zhangjiakou.aliyuncs.com +rayBucketName=fancv-sys + +spring.servlet.multipart.enabled=true +spring.servlet.multipart.max-file-size=2048MB +spring.servlet.multipart.maxRequestSize=2048MB + + +dam.oss.accessKeyId=LTAI5t5sF7sXqD8by7p3RCRB +dam.oss.accessKeySecret=mwTXDxnvGGO6V5YcMzp80q8a5oH67l +dam.oss.bucketName=fancv-sys +dam.oss.ossEndPoint=oss-cn-zhangjiakou.aliyuncs.com +dam.oss.ossEndPointInner=oss-cn-zhangjiakou.aliyuncs.com + diff --git a/SpringBoot-OSS/target/classes/com/fancv/App.class b/SpringBoot-OSS/target/classes/com/fancv/App.class new file mode 100644 index 0000000..8418401 Binary files /dev/null and b/SpringBoot-OSS/target/classes/com/fancv/App.class differ diff --git a/SpringBoot-OSS/target/classes/com/fancv/config/Knife4jConfiguration.class b/SpringBoot-OSS/target/classes/com/fancv/config/Knife4jConfiguration.class new file mode 100644 index 0000000..9f78e2f Binary files /dev/null and b/SpringBoot-OSS/target/classes/com/fancv/config/Knife4jConfiguration.class differ diff --git a/SpringBoot-OSS/target/classes/com/fancv/config/UserDamOssClientConfig.class b/SpringBoot-OSS/target/classes/com/fancv/config/UserDamOssClientConfig.class new file mode 100644 index 0000000..490b68f Binary files /dev/null and b/SpringBoot-OSS/target/classes/com/fancv/config/UserDamOssClientConfig.class differ diff --git a/SpringBoot-OSS/target/classes/com/fancv/controller/ossController.class b/SpringBoot-OSS/target/classes/com/fancv/controller/ossController.class new file mode 100644 index 0000000..25a8b91 Binary files /dev/null and b/SpringBoot-OSS/target/classes/com/fancv/controller/ossController.class differ diff --git a/SpringBoot-OSS/target/classes/com/fancv/service/OssService.class b/SpringBoot-OSS/target/classes/com/fancv/service/OssService.class new file mode 100644 index 0000000..9988432 Binary files /dev/null and b/SpringBoot-OSS/target/classes/com/fancv/service/OssService.class differ diff --git a/SpringBoot-OSS/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/SpringBoot-OSS/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..e69de29 diff --git a/SpringBoot-OSS/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/SpringBoot-OSS/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..f8f4487 --- /dev/null +++ b/SpringBoot-OSS/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,5 @@ +D:\java\IdeaProjects\SpringBootCodeBase\SpringBoot-OSS\src\main\java\com\fancv\App.java +D:\java\IdeaProjects\SpringBootCodeBase\SpringBoot-OSS\src\main\java\com\fancv\service\OssService.java +D:\java\IdeaProjects\SpringBootCodeBase\SpringBoot-OSS\src\main\java\com\fancv\controller\ossController.java +D:\java\IdeaProjects\SpringBootCodeBase\SpringBoot-OSS\src\main\java\com\fancv\config\Knife4jConfiguration.java +D:\java\IdeaProjects\SpringBootCodeBase\SpringBoot-OSS\src\main\java\com\fancv\config\UserDamOssClientConfig.java diff --git a/SpringBoot-OSS/target/test-classes/com/fancv/AppTest.class b/SpringBoot-OSS/target/test-classes/com/fancv/AppTest.class new file mode 100644 index 0000000..3e80c19 Binary files /dev/null and b/SpringBoot-OSS/target/test-classes/com/fancv/AppTest.class differ diff --git a/SpringBoot-OSS/target/test-classes/com/fancv/Demo.class b/SpringBoot-OSS/target/test-classes/com/fancv/Demo.class new file mode 100644 index 0000000..6f4cd1e Binary files /dev/null and b/SpringBoot-OSS/target/test-classes/com/fancv/Demo.class differ diff --git a/SpringBoot-PgSQL/pom.xml b/SpringBoot-PgSQL/pom.xml new file mode 100644 index 0000000..1ec9c34 --- /dev/null +++ b/SpringBoot-PgSQL/pom.xml @@ -0,0 +1,97 @@ + + + + + SpringBootCodeBase + com.fancv + 1.0-SNAPSHOT + + 4.0.0 + + SpringBoot-PgSQL + + SpringBoot-PgSQL + + http://www.fancv.com + + + UTF-8 + 11 + 11 + + + + + junit + junit + 4.11 + test + + + org.springframework.boot + spring-boot-starter-web + + + org.postgresql + postgresql + + + com.alibaba + druid + 1.0.27 + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 1.1.1 + + + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + + diff --git a/SpringBoot-PgSQL/src/main/java/com/fancv/App.java b/SpringBoot-PgSQL/src/main/java/com/fancv/App.java new file mode 100644 index 0000000..7b406eb --- /dev/null +++ b/SpringBoot-PgSQL/src/main/java/com/fancv/App.java @@ -0,0 +1,17 @@ +package com.fancv; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * Hello world! + * + */ +@SpringBootApplication +public class App +{ + public static void main( String[] args ) + { + SpringApplication.run(App.class,args); + } +} diff --git a/SpringBoot-PgSQL/src/main/java/com/fancv/config/DataConfig.java b/SpringBoot-PgSQL/src/main/java/com/fancv/config/DataConfig.java new file mode 100644 index 0000000..f3f9942 --- /dev/null +++ b/SpringBoot-PgSQL/src/main/java/com/fancv/config/DataConfig.java @@ -0,0 +1,43 @@ +package com.fancv.config; + +import com.alibaba.druid.pool.DruidDataSource; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.jdbc.core.JdbcTemplate; + +import javax.sql.DataSource; + +@Configuration +public class DataConfig { + @Value("${spring.datasource.username}") + private String user; + @Value("${spring.datasource.password}") + private String pass; + @Value("${spring.datasource.url}") + private String url; + @Value("${spring.datasource.driver-class-name}") + private String driverClassName; + + @Bean(name = "data_pgsql") + public DataSource dataSource() { + return getDruidDataSource(user,pass,url,driverClassName); + } + + private DruidDataSource getDruidDataSource(String name, String password, String url, String driver){ + DruidDataSource druidDataSource = new DruidDataSource(); + druidDataSource.setDriverClassName(driver); + druidDataSource.setUrl(url); + druidDataSource.setUsername(name); + druidDataSource.setPassword(password); + return druidDataSource; + } + + @Bean(name = "jdbc_pgsql") + public JdbcTemplate getJdbcTemplate(@Qualifier("data_pgsql") DataSource dataSource) { + return new JdbcTemplate(dataSource); + } + +} + diff --git a/SpringBoot-PgSQL/src/main/java/com/fancv/controller/TestController.java b/SpringBoot-PgSQL/src/main/java/com/fancv/controller/TestController.java new file mode 100644 index 0000000..2fcf510 --- /dev/null +++ b/SpringBoot-PgSQL/src/main/java/com/fancv/controller/TestController.java @@ -0,0 +1,30 @@ +package com.fancv.controller; + +import io.swagger.annotations.Api; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.time.LocalDate; + +@RestController +@Api(tags = "1") +public class TestController { + + @Autowired + @Qualifier("jdbc_pgsql") + private JdbcTemplate jdbcTemplate; + + @GetMapping(value = "/getUser") + public Object get() { + + LocalDate date = LocalDate.now(); + + System.out.println(date.toString()); + String sql = "select * from public.user"; + return jdbcTemplate.queryForList(sql); + } +} + diff --git a/SpringBoot-PgSQL/src/main/resources/application.yaml b/SpringBoot-PgSQL/src/main/resources/application.yaml new file mode 100644 index 0000000..f56948b --- /dev/null +++ b/SpringBoot-PgSQL/src/main/resources/application.yaml @@ -0,0 +1,28 @@ +spring: + datasource: + username: 'postgres' + password: 'abc123' + url: jdbc:postgresql://127.0.0.1:5432/first + driver-class-name: org.postgresql.Driver + type: com.alibaba.druid.pool.DruidDataSource + initialSize: 5 + minIdle: 5 + maxActive: 20 + maxWait: 60000 + timeBetweenEvictionRunsMillis: 60000 + minEvictableIdleTimeMillis: 300000 + validationQuery: SELECT 1 FROM DUAL + testWhileIdle: true + testOnBorrow: false + testOnReturn: false + poolPreparedStatements: true + #配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙 + filters: stat,wall,log4j + maxPoolPreparedStatementPerConnectionSize: 20 + useGlobalDataSourceStat: true + connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500 + + +server: + port: 9019 + diff --git a/SpringBoot-PgSQL/src/test/java/com/fancv/AppTest.java b/SpringBoot-PgSQL/src/test/java/com/fancv/AppTest.java new file mode 100644 index 0000000..84d0c0b --- /dev/null +++ b/SpringBoot-PgSQL/src/test/java/com/fancv/AppTest.java @@ -0,0 +1,20 @@ +package com.fancv; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +/** + * Unit test for simple App. + */ +public class AppTest +{ + /** + * Rigorous Test :-) + */ + @Test + public void shouldAnswerWithTrue() + { + assertTrue( true ); + } +} diff --git a/SpringBoot-Redis/src/main/resources/application.properties b/SpringBoot-Redis/src/main/resources/application.properties deleted file mode 100644 index 0faaf5e..0000000 --- a/SpringBoot-Redis/src/main/resources/application.properties +++ /dev/null @@ -1,26 +0,0 @@ -# RedisӶ˿ -spring.redis.port=6379 -# Redisַ -spring.redis.host=127.0.0.1 -# RedisݿĬΪ0 -spring.redis.database=5 -# Redis루ĬΪգ -spring.redis.password= "" -# ӳʹøֵʾûƣ -spring.redis.jedis.pool.max-active=8 -# ӳȴʱ䣨ʹøֵʾûƣ -spring.redis.jedis.pool.max-wait=-1ms -# ӳе -spring.redis.jedis.pool.max-idle=8 -# ӳеС -spring.redis.jedis.pool.min-idle=0 -# ӳʱʱ䣨룩 -spring.redis.timeout=5000ms - -#redis ڱRedis Server -spring.redis.sentinel.master=devwj -# comma-separated list of host:port pairs ڱб -spring.redis.sentinel.nodes=192.168.5.86:28001,192.168.5.86:28002,192.168.5.86:28003 - -server.port=9093 - diff --git a/SpringBoot-Redis/src/main/resources/application.yaml b/SpringBoot-Redis/src/main/resources/application.yaml new file mode 100644 index 0000000..ea8e435 --- /dev/null +++ b/SpringBoot-Redis/src/main/resources/application.yaml @@ -0,0 +1,8 @@ +#redis 配置 +spring: + redis: + port: 6379 + host: 127.0.0.1 + database: 10 +server: + port: 9010 \ No newline at end of file diff --git a/SpringBoot-Security/pom.xml b/SpringBoot-Security/pom.xml new file mode 100644 index 0000000..1f184bd --- /dev/null +++ b/SpringBoot-Security/pom.xml @@ -0,0 +1,132 @@ + + + + + SpringBootCodeBase + com.fancv + 1.0-SNAPSHOT + + 4.0.0 + + SpringBoot-Security + + SpringBoot-Security + + http://www.example.com + + + UTF-8 + 11 + 11 + + + + + junit + junit + 4.11 + test + + + org.springframework.boot + spring-boot-starter-jdbc + 2.3.9.RELEASE + + + com.alibaba + druid-spring-boot-starter + 1.1.17 + + + org.springframework.boot + spring-boot-configuration-processor + 2.5.7 + + + + com.baomidou + mybatis-plus + 3.5.1 + + + mysql + mysql-connector-java + 8.0.19 + + + org.slf4j + log4j-over-slf4j + 1.7.25 + + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.cloud + spring-cloud-starter-oauth2 + 2.2.5.RELEASE + + + com.nimbusds + nimbus-jose-jwt + 8.16 + + + org.springframework.boot + spring-boot-starter-data-redis + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + + diff --git a/SpringBoot-Security/src/main/java/com/fancv/SpringSecurityApplicationStart.java b/SpringBoot-Security/src/main/java/com/fancv/SpringSecurityApplicationStart.java new file mode 100644 index 0000000..70daab7 --- /dev/null +++ b/SpringBoot-Security/src/main/java/com/fancv/SpringSecurityApplicationStart.java @@ -0,0 +1,21 @@ +package com.fancv; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +/** + * Hello world! + * + */ +@SpringBootApplication +@EnableResourceServer +@EnableSwagger2 +public class SpringSecurityApplicationStart +{ + public static void main( String[] args ) + { + SpringApplication.run(SpringSecurityApplicationStart.class,args); + } +} diff --git a/SpringBoot-Security/src/main/java/com/fancv/config/CustomTokenEnhancer.java b/SpringBoot-Security/src/main/java/com/fancv/config/CustomTokenEnhancer.java new file mode 100644 index 0000000..8833aa7 --- /dev/null +++ b/SpringBoot-Security/src/main/java/com/fancv/config/CustomTokenEnhancer.java @@ -0,0 +1,27 @@ +package com.fancv.config; + + +import org.springframework.security.core.Authentication; +import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; +import org.springframework.security.oauth2.common.OAuth2AccessToken; +import org.springframework.security.oauth2.provider.OAuth2Authentication; +import org.springframework.security.oauth2.provider.token.TokenEnhancer; + +import java.util.HashMap; +import java.util.Map; + +public class CustomTokenEnhancer implements TokenEnhancer { + + @Override + public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) { + Authentication userAuthentication = authentication.getUserAuthentication(); + if (userAuthentication != null) { + Object principal = authentication.getUserAuthentication().getPrincipal(); + //把用户标识嵌入JWT Token中去(Key是userDetails) + Map additionalInfo = new HashMap<>(); + additionalInfo.put("userDetails", principal); + ((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(additionalInfo); + } + return accessToken; + } +} \ No newline at end of file diff --git a/SpringBoot-Security/src/main/java/com/fancv/config/OAuth2ServerConfiguration.java b/SpringBoot-Security/src/main/java/com/fancv/config/OAuth2ServerConfiguration.java new file mode 100644 index 0000000..d63bcf6 --- /dev/null +++ b/SpringBoot-Security/src/main/java/com/fancv/config/OAuth2ServerConfiguration.java @@ -0,0 +1,154 @@ +package com.fancv.config; + + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.ClassPathResource; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.crypto.password.NoOpPasswordEncoder; +import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; +import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; +import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; +import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; +import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer; +import org.springframework.security.oauth2.provider.approval.JdbcApprovalStore; +import org.springframework.security.oauth2.provider.code.AuthorizationCodeServices; +import org.springframework.security.oauth2.provider.code.JdbcAuthorizationCodeServices; +import org.springframework.security.oauth2.provider.token.TokenEnhancer; +import org.springframework.security.oauth2.provider.token.TokenEnhancerChain; +import org.springframework.security.oauth2.provider.token.TokenStore; +import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; +import org.springframework.security.oauth2.provider.token.store.JwtTokenStore; +import org.springframework.security.oauth2.provider.token.store.KeyStoreKeyFactory; +import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +import javax.sql.DataSource; +import java.util.Arrays; + +@Configuration +@EnableAuthorizationServer //开启授权服务器 +public class OAuth2ServerConfiguration extends AuthorizationServerConfigurerAdapter { + @Autowired + private DataSource dataSource; + + @Autowired + private AuthenticationManager authenticationManager; + + @Autowired + private RedisConnectionFactory redisConnectionFactory; + + + + + /** + * 我们配置了使用数据库来维护客户端信息。虽然在各种Demo中我们经常看到的是在内存中维护客户端信息,通过配置直接写死在这里。 + * 但是,对于实际的应用我们一般都会用数据库来维护这个信息,甚至还会建立一套工作流来允许客户端自己申请ClientID,实现OAuth客户端接入的审批。 + * @param clients + * @throws Exception + */ + @Override + public void configure(ClientDetailsServiceConfigurer clients) throws Exception { + clients.jdbc(dataSource); + } + + /** + * 这里干了两件事儿。首先,打开了验证Token的访问权限(以便之后我们演示)。 + * 然后,允许ClientSecret明文方式保存,并且可以通过表单提交(而不仅仅是Basic Auth方式提交),之后会演示到这个。 + * @param security + * @throws Exception + */ + @Override + public void configure(AuthorizationServerSecurityConfigurer security) throws Exception { + security.checkTokenAccess("permitAll()") + .allowFormAuthenticationForClients().passwordEncoder(NoOpPasswordEncoder.getInstance()); + } + + /** + * 干了以下4件事儿: + * 1. 配置我们的令牌存放方式为JWT方式,而不是内存、数据库或Redis方式。 + * JWT是Json Web Token的缩写,也就是使用JSON数据格式包装的令牌,由.号把整个JWT分隔为头、数据体、签名三部分。 + * JWT保存Token虽然易于使用但是不是那么安全,一般用于内部,且需要走HTTPS并配置比较短的失效时间。 + * 2. 配置JWT Token的非对称加密来进行签名 + * 3. 配置一个自定义的Token增强器,把更多信息放入Token中 + * 4. 配置使用JDBC数据库方式来保存用户的授权批准记录 + * @param endpoints + * @throws Exception + */ + @Override + public void configure(AuthorizationServerEndpointsConfigurer endpoints) { + TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain(); + tokenEnhancerChain.setTokenEnhancers( + Arrays.asList(tokenEnhancer())); + + endpoints.approvalStore(approvalStore()) + .authorizationCodeServices(authorizationCodeServices()) + .tokenStore(tokenStore()) + .tokenEnhancer(tokenEnhancerChain) + .authenticationManager(authenticationManager); + } + + /** + * 使用JDBC数据库方式来保存授权码 + * @return + */ + @Bean + public AuthorizationCodeServices authorizationCodeServices() { + return new JdbcAuthorizationCodeServices(dataSource); + } + + /** + * 使用Redis存储 + * @return + */ + @Bean + public TokenStore tokenStore() { + RedisTokenStore redisTokenStore = new RedisTokenStore(redisConnectionFactory); + redisTokenStore.setPrefix("auth-token:"); + return redisTokenStore; + } + + /** + * 使用JDBC数据库方式来保存用户的授权批准记录 + * @return + */ + @Bean + public JdbcApprovalStore approvalStore() { + return new JdbcApprovalStore(dataSource); + } + + /** + * 自定义的Token增强器,把更多信息放入Token中 + * @return + */ + @Bean + public TokenEnhancer tokenEnhancer() { + return new CustomTokenEnhancer(); + } + + /** + * 配置JWT使用非对称加密方式来验证 + * @return + */ + /* @Bean + protected JwtAccessTokenConverter jwtTokenEnhancer() { + KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(new ClassPathResource("jwt.jks"), "2022qw".toCharArray()); + JwtAccessTokenConverter converter = new JwtAccessTokenConverter(); + converter.setKeyPair(keyStoreKeyFactory.getKeyPair("jwt")); + return converter; + }*/ + + /** + * 配置登录页面的视图信息(其实可以独立一个配置类,这样会更规范) + */ + @Configuration + static class MvcConfig implements WebMvcConfigurer { + @Override + public void addViewControllers(ViewControllerRegistry registry) { + registry.addViewController("login").setViewName("login"); + } + } +} diff --git a/SpringBoot-Security/src/main/java/com/fancv/config/WebSecurityConfig.java b/SpringBoot-Security/src/main/java/com/fancv/config/WebSecurityConfig.java new file mode 100644 index 0000000..1aa47f6 --- /dev/null +++ b/SpringBoot-Security/src/main/java/com/fancv/config/WebSecurityConfig.java @@ -0,0 +1,71 @@ +package com.fancv.config; + + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.builders.WebSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; + +import javax.sql.DataSource; + +@Configuration +@EnableWebSecurity +public class WebSecurityConfig extends WebSecurityConfigurerAdapter { + @Autowired + private DataSource dataSource; + + @Override + @Bean + public AuthenticationManager authenticationManagerBean() throws Exception { + return super.authenticationManagerBean(); + } + + /** + * 配置用户账户的认证方式。显然,我们把用户存在了数据库中希望配置JDBC的方式。 + * 此外,我们还配置了使用BCryptPasswordEncoder哈希来保存用户的密码(生产环境中,用户密码肯定不能是明文保存的) + * @param auth + * @throws Exception + */ + @Override + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + auth.jdbcAuthentication() + .dataSource(dataSource) + .passwordEncoder(new BCryptPasswordEncoder()); + } + + /** + * 开放/login和/oauth/authorize两个路径的匿名访问。前者用于登录,后者用于换授权码,这两个端点访问的时机都在登录之前。 + * 设置/login使用表单验证进行登录。 未生效 + * @param http + * @throws Exception + */ + @Override + protected void configure(HttpSecurity http) throws Exception { + + http.authorizeRequests() + .antMatchers("/login/**").permitAll()// 配置拦截规则 + .anyRequest().authenticated(); + +// http.authorizeRequests() +// .antMatchers("/login") +// .permitAll() +// .anyRequest().authenticated() +// .and() +// .formLogin().loginPage("/login"); + } + /*** + * 核心过滤器配置方法 + * @param web + * @throws Exception + */ + @Override + public void configure(WebSecurity web) throws Exception { + super.configure(web); + } +} \ No newline at end of file diff --git a/SpringBoot-Security/src/main/java/com/fancv/controller/UserInfoController.java b/SpringBoot-Security/src/main/java/com/fancv/controller/UserInfoController.java new file mode 100644 index 0000000..7fb06c9 --- /dev/null +++ b/SpringBoot-Security/src/main/java/com/fancv/controller/UserInfoController.java @@ -0,0 +1,15 @@ +package com.fancv.controller; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("user/") +public class UserInfoController { + + @GetMapping("list") + public String userList(){ + return "ok"; + } +} diff --git a/SpringBoot-Security/src/main/resources/application.yaml b/SpringBoot-Security/src/main/resources/application.yaml new file mode 100644 index 0000000..8c933c6 --- /dev/null +++ b/SpringBoot-Security/src/main/resources/application.yaml @@ -0,0 +1,40 @@ +spring: + redis: + host: 127.0.0.1 + database: 1 + port: 6379 + datasource: + username: 'admin' + password: 'hta@123' + url: jdbc:mysql://127.0.0.1:3306/spring_security?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC&zeroDateTimeBehavior=convertToNull + driver-class-name: com.mysql.cj.jdbc.Driver + type: com.alibaba.druid.pool.DruidDataSource + initialSize: 5 + minIdle: 5 + maxActive: 20 + maxWait: 60000 + timeBetweenEvictionRunsMillis: 60000 + minEvictableIdleTimeMillis: 300000 + validationQuery: SELECT 1 FROM DUAL + testWhileIdle: true + testOnBorrow: false + testOnReturn: false + poolPreparedStatements: true + #配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙 + filters: stat,wall,log4j + maxPoolPreparedStatementPerConnectionSize: 20 + useGlobalDataSourceStat: true + connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500 + db2: + username: admin + password: hta@123 + url: jdbc:mysql://localhost:3306/spring_security?useUnicode=true&characterEncoding=utf-8&useSSL=false + driver-class-name: com.mysql.cj.jdbc.Driver + +server: + port: 9011 + + +logging: + level: + root: info \ No newline at end of file diff --git a/SpringBoot-Security/src/main/resources/jwt.jks b/SpringBoot-Security/src/main/resources/jwt.jks new file mode 100644 index 0000000..9bfeb9c Binary files /dev/null and b/SpringBoot-Security/src/main/resources/jwt.jks differ diff --git a/SpringBoot-Security/src/main/resources/templates/login.html b/SpringBoot-Security/src/main/resources/templates/login.html new file mode 100644 index 0000000..b1183c4 --- /dev/null +++ b/SpringBoot-Security/src/main/resources/templates/login.html @@ -0,0 +1,37 @@ + + + + + OAuth2 Demo + + + + + +
+
+

Login Form

+ +

+ 用户名或密码错误... +

+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ + + diff --git a/SpringBoot-Security/src/test/java/com/fancv/SpringSecurityApplicationStartTest.java b/SpringBoot-Security/src/test/java/com/fancv/SpringSecurityApplicationStartTest.java new file mode 100644 index 0000000..2100f4a --- /dev/null +++ b/SpringBoot-Security/src/test/java/com/fancv/SpringSecurityApplicationStartTest.java @@ -0,0 +1,20 @@ +package com.fancv; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +/** + * Unit test for simple App. + */ +public class SpringSecurityApplicationStartTest +{ + /** + * Rigorous Test :-) + */ + @Test + public void shouldAnswerWithTrue() + { + assertTrue( true ); + } +} diff --git a/SpringBoot-mybatis-plus/src/main/resources/mapper/PeopleConfigMapper.xml b/SpringBoot-mybatis-plus/src/main/resources/mapper/PeopleConfigMapper.xml new file mode 100644 index 0000000..d5eed5e --- /dev/null +++ b/SpringBoot-mybatis-plus/src/main/resources/mapper/PeopleConfigMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/SpringBoot-mybatis-plus/src/main/resources/mapper/TUserMapper.xml b/SpringBoot-mybatis-plus/src/main/resources/mapper/TUserMapper.xml new file mode 100644 index 0000000..132afb4 --- /dev/null +++ b/SpringBoot-mybatis-plus/src/main/resources/mapper/TUserMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/SpringBoot-mybatis-plus/src/main/resources/mapper/TenantInfoMapper.xml b/SpringBoot-mybatis-plus/src/main/resources/mapper/TenantInfoMapper.xml new file mode 100644 index 0000000..213266b --- /dev/null +++ b/SpringBoot-mybatis-plus/src/main/resources/mapper/TenantInfoMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/SpringBoot-mybatis-plus/src/test/java/com/fancv/AppTest.java b/SpringBoot-mybatis-plus/src/test/java/com/fancv/AppTest.java new file mode 100644 index 0000000..84d0c0b --- /dev/null +++ b/SpringBoot-mybatis-plus/src/test/java/com/fancv/AppTest.java @@ -0,0 +1,20 @@ +package com.fancv; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +/** + * Unit test for simple App. + */ +public class AppTest +{ + /** + * Rigorous Test :-) + */ + @Test + public void shouldAnswerWithTrue() + { + assertTrue( true ); + } +} diff --git a/SpringBoot-mybatis-plus/target/classes/META-INF/spring-configuration-metadata.json b/SpringBoot-mybatis-plus/target/classes/META-INF/spring-configuration-metadata.json new file mode 100644 index 0000000..004fc68 --- /dev/null +++ b/SpringBoot-mybatis-plus/target/classes/META-INF/spring-configuration-metadata.json @@ -0,0 +1,18 @@ +{ + "groups": [ + { + "name": "spring.datasource", + "type": "javax.sql.DataSource", + "sourceType": "com.fancv.config.DataSourceConfig", + "sourceMethod": "dataSource()" + }, + { + "name": "spring.datasource.db2", + "type": "javax.sql.DataSource", + "sourceType": "com.fancv.config.DataSourceConfig", + "sourceMethod": "dataSource2()" + } + ], + "properties": [], + "hints": [] +} \ No newline at end of file diff --git a/SpringBoot-mybatis-plus/target/classes/application.yaml b/SpringBoot-mybatis-plus/target/classes/application.yaml new file mode 100644 index 0000000..974051b --- /dev/null +++ b/SpringBoot-mybatis-plus/target/classes/application.yaml @@ -0,0 +1,32 @@ +spring: + datasource: + username: 'admin' + password: 'hta@123' + url: jdbc:mysql://127.0.0.1:3306/mysql8_study?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC&zeroDateTimeBehavior=convertToNull + driver-class-name: com.mysql.cj.jdbc.Driver + type: com.alibaba.druid.pool.DruidDataSource + initialSize: 5 + minIdle: 5 + maxActive: 20 + maxWait: 60000 + timeBetweenEvictionRunsMillis: 60000 + minEvictableIdleTimeMillis: 300000 + validationQuery: SELECT 1 FROM DUAL + testWhileIdle: true + testOnBorrow: false + testOnReturn: false + poolPreparedStatements: true + #配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙 + filters: stat,wall,log4j + maxPoolPreparedStatementPerConnectionSize: 20 + useGlobalDataSourceStat: true + connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500 + db2: + username: admin + password: hta@123 + url: jdbc:mysql://localhost:3306/mysql8_study?useUnicode=true&characterEncoding=utf-8&useSSL=false + driver-class-name: com.mysql.cj.jdbc.Driver + +server: + port: 9011 + diff --git a/SpringBoot-mybatis-plus/target/classes/com/fancv/SpringBootMybatisPlusApp.class b/SpringBoot-mybatis-plus/target/classes/com/fancv/SpringBootMybatisPlusApp.class new file mode 100644 index 0000000..684d46a Binary files /dev/null and b/SpringBoot-mybatis-plus/target/classes/com/fancv/SpringBootMybatisPlusApp.class differ diff --git a/SpringBoot-mybatis-plus/target/classes/com/fancv/config/DataSourceConfig.class b/SpringBoot-mybatis-plus/target/classes/com/fancv/config/DataSourceConfig.class new file mode 100644 index 0000000..08688ca Binary files /dev/null and b/SpringBoot-mybatis-plus/target/classes/com/fancv/config/DataSourceConfig.class differ diff --git a/SpringBoot-mybatis-plus/target/classes/com/fancv/config/DateAutoFillHandler.class b/SpringBoot-mybatis-plus/target/classes/com/fancv/config/DateAutoFillHandler.class new file mode 100644 index 0000000..63ac05b Binary files /dev/null and b/SpringBoot-mybatis-plus/target/classes/com/fancv/config/DateAutoFillHandler.class differ diff --git a/SpringBoot-mybatis-plus/target/classes/com/fancv/config/MyBatisPlusConfig.class b/SpringBoot-mybatis-plus/target/classes/com/fancv/config/MyBatisPlusConfig.class new file mode 100644 index 0000000..6caadfd Binary files /dev/null and b/SpringBoot-mybatis-plus/target/classes/com/fancv/config/MyBatisPlusConfig.class differ diff --git a/SpringBoot-mybatis-plus/target/classes/com/fancv/controller/MybatisPlusController.class b/SpringBoot-mybatis-plus/target/classes/com/fancv/controller/MybatisPlusController.class new file mode 100644 index 0000000..83d1266 Binary files /dev/null and b/SpringBoot-mybatis-plus/target/classes/com/fancv/controller/MybatisPlusController.class differ diff --git a/SpringBoot-mybatis-plus/target/classes/com/fancv/dao/User.class b/SpringBoot-mybatis-plus/target/classes/com/fancv/dao/User.class new file mode 100644 index 0000000..2e017ba Binary files /dev/null and b/SpringBoot-mybatis-plus/target/classes/com/fancv/dao/User.class differ diff --git a/SpringBoot-mybatis-plus/target/classes/com/fancv/mapper/UserMapper.class b/SpringBoot-mybatis-plus/target/classes/com/fancv/mapper/UserMapper.class new file mode 100644 index 0000000..723c488 Binary files /dev/null and b/SpringBoot-mybatis-plus/target/classes/com/fancv/mapper/UserMapper.class differ diff --git a/SpringBoot-mybatis-plus/target/classes/com/fancv/monitor/SqlPrintInterceptor$1.class b/SpringBoot-mybatis-plus/target/classes/com/fancv/monitor/SqlPrintInterceptor$1.class new file mode 100644 index 0000000..5080410 Binary files /dev/null and b/SpringBoot-mybatis-plus/target/classes/com/fancv/monitor/SqlPrintInterceptor$1.class differ diff --git a/SpringBoot-mybatis-plus/target/classes/com/fancv/monitor/SqlPrintInterceptor.class b/SpringBoot-mybatis-plus/target/classes/com/fancv/monitor/SqlPrintInterceptor.class new file mode 100644 index 0000000..77a0a13 Binary files /dev/null and b/SpringBoot-mybatis-plus/target/classes/com/fancv/monitor/SqlPrintInterceptor.class differ diff --git a/SpringBoot-mybatis-plus/target/classes/com/fancv/service/UserService.class b/SpringBoot-mybatis-plus/target/classes/com/fancv/service/UserService.class new file mode 100644 index 0000000..b107da9 Binary files /dev/null and b/SpringBoot-mybatis-plus/target/classes/com/fancv/service/UserService.class differ diff --git a/SpringBoot-mybatis-plus/target/test-classes/com/fancv/AppTest.class b/SpringBoot-mybatis-plus/target/test-classes/com/fancv/AppTest.class new file mode 100644 index 0000000..739dbd8 Binary files /dev/null and b/SpringBoot-mybatis-plus/target/test-classes/com/fancv/AppTest.class differ diff --git a/SpringBoot-rocketMQ-consumer/src/test/java/com/fancv/AppTest.java b/SpringBoot-rocketMQ-consumer/src/test/java/com/fancv/AppTest.java new file mode 100644 index 0000000..84d0c0b --- /dev/null +++ b/SpringBoot-rocketMQ-consumer/src/test/java/com/fancv/AppTest.java @@ -0,0 +1,20 @@ +package com.fancv; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +/** + * Unit test for simple App. + */ +public class AppTest +{ + /** + * Rigorous Test :-) + */ + @Test + public void shouldAnswerWithTrue() + { + assertTrue( true ); + } +} diff --git a/SpringBoot-rocketMQ-consumer/target/classes/application.yaml b/SpringBoot-rocketMQ-consumer/target/classes/application.yaml new file mode 100644 index 0000000..9660dd6 --- /dev/null +++ b/SpringBoot-rocketMQ-consumer/target/classes/application.yaml @@ -0,0 +1,14 @@ +server: + servlet: + application-display-name: Rocket-Consumer + port: 9021 +spring: + application: + name: springboot-rocketMq-Consumer + + +rocketmq: + name-server: 192.168.0.23:9876 + consumer: + group: consumer-group-1 + diff --git a/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/RocketMQConsumerApp.class b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/RocketMQConsumerApp.class new file mode 100644 index 0000000..9b196c7 Binary files /dev/null and b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/RocketMQConsumerApp.class differ diff --git a/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/Consumer.class b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/Consumer.class new file mode 100644 index 0000000..d846729 Binary files /dev/null and b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/Consumer.class differ diff --git a/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/ConsumerService.class b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/ConsumerService.class new file mode 100644 index 0000000..f9d8553 Binary files /dev/null and b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/ConsumerService.class differ diff --git a/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/MqConsumerApplication.class b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/MqConsumerApplication.class new file mode 100644 index 0000000..31e9f68 Binary files /dev/null and b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/MqConsumerApplication.class differ diff --git a/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/bean/OrderNotifyEvent.class b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/bean/OrderNotifyEvent.class new file mode 100644 index 0000000..c1b4527 Binary files /dev/null and b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/bean/OrderNotifyEvent.class differ diff --git a/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener$MyAsyncConsumer1.class b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener$MyAsyncConsumer1.class new file mode 100644 index 0000000..23d1045 Binary files /dev/null and b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener$MyAsyncConsumer1.class differ diff --git a/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener$MyAsyncConsumer2.class b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener$MyAsyncConsumer2.class new file mode 100644 index 0000000..ba7eccf Binary files /dev/null and b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener$MyAsyncConsumer2.class differ diff --git a/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener$MyAsyncConsumer3.class b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener$MyAsyncConsumer3.class new file mode 100644 index 0000000..a60064c Binary files /dev/null and b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener$MyAsyncConsumer3.class differ diff --git a/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener$MyConsumer1.class b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener$MyConsumer1.class new file mode 100644 index 0000000..4f004f9 Binary files /dev/null and b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener$MyConsumer1.class differ diff --git a/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener$MyConsumer2.class b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener$MyConsumer2.class new file mode 100644 index 0000000..05ea545 Binary files /dev/null and b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener$MyConsumer2.class differ diff --git a/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener$MyOneWayConsumer.class b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener$MyOneWayConsumer.class new file mode 100644 index 0000000..7fe142c Binary files /dev/null and b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener$MyOneWayConsumer.class differ diff --git a/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener$MyTagConsumer.class b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener$MyTagConsumer.class new file mode 100644 index 0000000..12bd7d6 Binary files /dev/null and b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener$MyTagConsumer.class differ diff --git a/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener$SycnConsumer.class b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener$SycnConsumer.class new file mode 100644 index 0000000..52781aa Binary files /dev/null and b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener$SycnConsumer.class differ diff --git a/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener$TransactionalConsumer.class b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener$TransactionalConsumer.class new file mode 100644 index 0000000..a9fbe3e Binary files /dev/null and b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener$TransactionalConsumer.class differ diff --git a/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener.class b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener.class new file mode 100644 index 0000000..ff001da Binary files /dev/null and b/SpringBoot-rocketMQ-consumer/target/classes/com/fancv/mq/listener/MessageListener.class differ diff --git a/SpringBoot-rocketMQ-consumer/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/SpringBoot-rocketMQ-consumer/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..7155caf --- /dev/null +++ b/SpringBoot-rocketMQ-consumer/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,15 @@ +com\fancv\mq\MqConsumerApplication.class +com\fancv\mq\bean\OrderNotifyEvent.class +com\fancv\mq\listener\MessageListener$TransactionalConsumer.class +com\fancv\mq\listener\MessageListener$MyTagConsumer.class +com\fancv\mq\listener\MessageListener$MyConsumer1.class +com\fancv\mq\listener\MessageListener$MyAsyncConsumer1.class +com\fancv\mq\ConsumerService.class +com\fancv\mq\listener\MessageListener$MyAsyncConsumer2.class +com\fancv\mq\listener\MessageListener$MyOneWayConsumer.class +com\fancv\RocketMQConsumerApp.class +com\fancv\mq\listener\MessageListener$MyAsyncConsumer3.class +com\fancv\mq\Consumer.class +com\fancv\mq\listener\MessageListener.class +com\fancv\mq\listener\MessageListener$MyConsumer2.class +com\fancv\mq\listener\MessageListener$SycnConsumer.class diff --git a/SpringBoot-rocketMQ-consumer/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/SpringBoot-rocketMQ-consumer/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..0b70a18 --- /dev/null +++ b/SpringBoot-rocketMQ-consumer/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,6 @@ +D:\java\IdeaProjects\SpringBootCodeBase\SpringBoot-rocketMQ-consumer\src\main\java\com\fancv\mq\bean\OrderNotifyEvent.java +D:\java\IdeaProjects\SpringBootCodeBase\SpringBoot-rocketMQ-consumer\src\main\java\com\fancv\mq\Consumer.java +D:\java\IdeaProjects\SpringBootCodeBase\SpringBoot-rocketMQ-consumer\src\main\java\com\fancv\mq\ConsumerService.java +D:\java\IdeaProjects\SpringBootCodeBase\SpringBoot-rocketMQ-consumer\src\main\java\com\fancv\mq\MqConsumerApplication.java +D:\java\IdeaProjects\SpringBootCodeBase\SpringBoot-rocketMQ-consumer\src\main\java\com\fancv\RocketMQConsumerApp.java +D:\java\IdeaProjects\SpringBootCodeBase\SpringBoot-rocketMQ-consumer\src\main\java\com\fancv\mq\listener\MessageListener.java diff --git a/SpringBoot-rocketMQ-consumer/target/test-classes/com/fancv/AppTest.class b/SpringBoot-rocketMQ-consumer/target/test-classes/com/fancv/AppTest.class new file mode 100644 index 0000000..739dbd8 Binary files /dev/null and b/SpringBoot-rocketMQ-consumer/target/test-classes/com/fancv/AppTest.class differ diff --git a/pom.xml b/pom.xml index e474a51..2317556 100644 --- a/pom.xml +++ b/pom.xml @@ -30,6 +30,9 @@ SpringBoot-mybatis-plus SpringBoot-OSS SpringBoot-Commons + SpringBoot-DynamicDataSource + SpringBoot-Security + SpringBoot-JavaReactor