From 5fd13e10b5a03fcaa370603bb7b821d2afcbd691 Mon Sep 17 00:00:00 2001 From: Andy Date: Sun, 18 Sep 2022 17:10:52 +0800 Subject: [PATCH 1/6] =?UTF-8?q?feature:spring=20cache=20redis=20=E8=AF=B4?= =?UTF-8?q?=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SpringBoot-MyBatis-Advances/Readme.md | 2 ++ 1 file changed, 2 insertions(+) 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 类型的实现,满足常用的配置、数据字典、类目等常见缓存场景的使用。 From e2417914050aa1c76330d1cab7a509be12d9ac43 Mon Sep 17 00:00:00 2001 From: Andy Date: Sun, 18 Sep 2022 17:11:25 +0800 Subject: [PATCH 2/6] feature:spring security --- .../src/main/java/com/fancv/SpringSecurityApplicationStart.java | 2 ++ .../src/main/java/com/fancv/config/WebSecurityConfig.java | 2 +- SpringBoot-Security/src/main/resources/application.yaml | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/SpringBoot-Security/src/main/java/com/fancv/SpringSecurityApplicationStart.java b/SpringBoot-Security/src/main/java/com/fancv/SpringSecurityApplicationStart.java index 8940b00..70daab7 100644 --- a/SpringBoot-Security/src/main/java/com/fancv/SpringSecurityApplicationStart.java +++ b/SpringBoot-Security/src/main/java/com/fancv/SpringSecurityApplicationStart.java @@ -3,6 +3,7 @@ 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! @@ -10,6 +11,7 @@ */ @SpringBootApplication @EnableResourceServer +@EnableSwagger2 public class SpringSecurityApplicationStart { public static void main( String[] args ) diff --git a/SpringBoot-Security/src/main/java/com/fancv/config/WebSecurityConfig.java b/SpringBoot-Security/src/main/java/com/fancv/config/WebSecurityConfig.java index be4e852..1aa47f6 100644 --- a/SpringBoot-Security/src/main/java/com/fancv/config/WebSecurityConfig.java +++ b/SpringBoot-Security/src/main/java/com/fancv/config/WebSecurityConfig.java @@ -41,7 +41,7 @@ protected void configure(AuthenticationManagerBuilder auth) throws Exception { /** * 开放/login和/oauth/authorize两个路径的匿名访问。前者用于登录,后者用于换授权码,这两个端点访问的时机都在登录之前。 - * 设置/login使用表单验证进行登录。 + * 设置/login使用表单验证进行登录。 未生效 * @param http * @throws Exception */ diff --git a/SpringBoot-Security/src/main/resources/application.yaml b/SpringBoot-Security/src/main/resources/application.yaml index b9281ae..8c933c6 100644 --- a/SpringBoot-Security/src/main/resources/application.yaml +++ b/SpringBoot-Security/src/main/resources/application.yaml @@ -37,4 +37,4 @@ server: logging: level: - root: debug \ No newline at end of file + root: info \ No newline at end of file From 821ad57480f6665caa17d17afd2b35b51b8f3645 Mon Sep 17 00:00:00 2001 From: Andy Date: Sun, 18 Sep 2022 17:14:41 +0800 Subject: [PATCH 3/6] feature:spring oss --- .gitignore | 6 +++++ .../src/main/resources/application.properties | 18 +++---------- .../src/main/resources/application.properties | 26 ------------------- .../src/main/resources/application.yaml | 8 ++++++ pom.xml | 1 + 5 files changed, 19 insertions(+), 40 deletions(-) delete mode 100644 SpringBoot-Redis/src/main/resources/application.properties create mode 100644 SpringBoot-Redis/src/main/resources/application.yaml 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-OSS/src/main/resources/application.properties b/SpringBoot-OSS/src/main/resources/application.properties index 11ca3a1..47dc664 100644 --- a/SpringBoot-OSS/src/main/resources/application.properties +++ b/SpringBoot-OSS/src/main/resources/application.properties @@ -1,35 +1,25 @@ 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=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= 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/pom.xml b/pom.xml index a769ffb..03a1ae8 100644 --- a/pom.xml +++ b/pom.xml @@ -31,6 +31,7 @@ SpringBoot-OSS SpringBoot-Commons SpringBoot-DynamicDataSource + SpringBoot-Security From 972d7a934fa59d0d3554d1b1d9b3155d554a331a Mon Sep 17 00:00:00 2001 From: Andy Date: Sat, 1 Oct 2022 13:16:12 +0800 Subject: [PATCH 4/6] feature:add maven template --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 03a1ae8..2317556 100644 --- a/pom.xml +++ b/pom.xml @@ -32,6 +32,7 @@ SpringBoot-Commons SpringBoot-DynamicDataSource SpringBoot-Security + SpringBoot-JavaReactor From 795df9918b8b39a2c60575ed6c002a8dc9572519 Mon Sep 17 00:00:00 2001 From: Andy Date: Thu, 5 Jan 2023 00:18:40 +0800 Subject: [PATCH 5/6] =?UTF-8?q?feature:spring=20mvc=20=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SpringBoot-AOP/pom.xml | 8 ++++ .../GlobalExceptionHandler.java | 37 ++++++++++++++++++ .../fancv/ExceptionHandler/ResultBody.java | 2 + .../fancv/controller/UserListController.java | 19 +++++++-- .../java/com/fancv/login/BaseUserDTO.java | 9 ++++- .../main/java/com/fancv/login/EnterDTO.java | 17 ++++++++ .../GlobalExceptionHandler.class | Bin 2496 -> 4173 bytes .../fancv/controller/UserListController.class | Bin 1548 -> 2263 bytes .../classes/com/fancv/login/BaseUserDTO.class | Bin 3604 -> 4411 bytes 9 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 SpringBoot-AOP/src/main/java/com/fancv/login/EnterDTO.java 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 ba749beedf9ef923c0f39e4c78d5f148bdcf103f..783254f5c675e0b5c25da39217e9d12840636232 100644 GIT binary patch literal 4173 zcmbuC`%@EF6vw}pS3+0?BPdEA)F&vqpw?DGX+sD?4TOeBMQrJkEMal83!4oO?MwU6 zTC3Aef9TlG*#6KT+F#nr3`NK3AJD&}==3N5gHF%gU6KH40Lu(}?>&3&IiGv(z2|KH z{O7?R0A9jv51vC$Ico8`8)rNSp|=8k2=iXQ2X7$a#sHT@%W)QiT=J$H=lEdAgYy{X zQ!nt|TNQX4BObg1$%9e*MU4029>^H>U<|`9Bs>_0;>HA@chL>ijid`2Lz${460*VI z4e3TgOsQihCd7~>^O3OgY=5XH;Ex7J&IE@>0^!ae*PM{1B~g{Mgg9Utik2YF%6@;u z-#gOf?+H0-m4p6JPp3cH6Yg^)Wo?S4nC%S34UK~gB>_Dy)69^f$$jbMsBA=~QI#Zw z5|h+H$x!&%5tf+aN{ZolD5fXHF-eO}i^18LJZUPr)-7pqRW`)asy-^ItHngOeN?%$ zTFfxlV69|UOv%QyDx2cCX-&JW}j{j zN~#jiC^94(3U9?a1~w72_W$RIPNlshYX#P6%vnZwIox!>l(_X)%%ivo+yl;qTgM>7 z9vdq_r_?kgI#Yv+uCC@gmxr&=j7@-wYe5TIW^lK~R42cB2K2NMle-k2P3!V!#iRV* zZ06#Vd(+TW%Cr9Xv=Wnj0`}v8fag)quy^V9myf@```6-~r5isiJ-oWKxcKDZm8DyE zm%jb}(Ko+5d3fjYdoJh#CNbrLAs_`)K$;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K&N)0y6&>@n_U{k%KyS_8wTWsB{rf2QO+ zW6Qgdga(hC`Ut8MEVgpCNHr#JPuaomcozbETIEb9WR^C;_Cdf?+NIJ#c~Z2vpLXa} zwV`~2^djk~z93x$Kj;-bqa&G-qm$>NE=WJ)3yl!aB~L7Lw}^W7@D4@vLO73J`qWDB zw!C$0e2E_i!#8A7T;h(i;n8D;KI$n}Wr!;o;!1{CEQ_^dC{{A`YX+f((slVUYh ugVjJSRs)Guz+h!9UCDjPEyd9_Pp>GLp(zO diff --git a/SpringBoot-AOP/target/classes/com/fancv/controller/UserListController.class b/SpringBoot-AOP/target/classes/com/fancv/controller/UserListController.class index 08844895a32776b70034ffbcab13a06cc8feeeeb..e1454a7d2a0e4eb3c1c87a4e99fdd0633c50a36e 100644 GIT binary patch literal 2263 zcmb7G+g2M@82)w=NJyrDp@8&ci?mG&GGGr>K@_M|+HjCiYFk~don#1ulbJX(fyJeF zF0Z`t!Yg0F>P1_tK7j90z4Q%SetRY)Ay^lMH8cPI=RbV^aq`DMzx)nh3ZEr$0`JH1 zK@t(nB`}}D0&XSnVHZ+ZOyV{^N?{3i61W>jE{SEV#IY(6wVbj*I_J1$-Ltl??dUnD zTsGWkfzBDzHvL)3WU`wAu?44O2=wGk+gPbp3WmEO3l=$4E=p@tx~4kUnK6Ic^aQfG zqEpegq+Q(Ai;nHPj%69He$O-9oay-s4Ho?+YIUx_NG7)H*}DHrbh@MrY}?ciHf_ozj|gWySCfmr-`* z&9W{1n#*k5JO=caSRPuh*}hpZHciiDCg*J1@uhD%HeFl~D^yjf*ixSN9QO--&nV~x z(=O?Pd*Vh_k(03XIx#UR zFqvtIH-MqfOV3d4cWYzyprsDOO%<9F0%!l%fIvL3`Z;|aze087^G<1>!2es1Wiv}b z@mp)l;1t&=Q7{4)o3El8l%=HuRnO=G zXL6>adwWuCmzJ13eXeRUoR}}mtbga^xRTeu+Ct^TXf2ex;!sJ#lPkxQER+?rZo24+J8scLgpVb1B8~ zP{Sj9%As%Wm({|KQRFDaGD~VLb~hm^bljG*#EsP7Ivt_PboQaZkaEo`7GyzkFM9rt z$N9UHUtM7f`;H>Qeb+W%2PTg0B!X*S-UMgbTTUB_gFQ;ngY6oNvgkYRJ}10v_~92o z;9_eG3zqaePE5PzG%oN9bAlfsfm15yq&i5me!Qo7()kpMd*unlV-gYc@!lCQPvRtL zEfhdM26!SqypC9)TtSroK>u?@9`q)kAi6x3jy*$11oy{&;^RE82!k8ubCA@VR2_K);o%}Kk-qF9 z!$%fZ>QJY6icmP3?o_~9qZ|$Z4TP^7fTDFkEl!oQZrW)&8^suTno8kYyvDsCpQD(l zd%aDg%4^S0h>t!+;u*RkNGF>J)DHp>sz#_P*CC3Y28td`;%!>4qnM<~Q507L6e$(p zH40qkmB5Wgi7!xJ{dJ{NPoe#cxGFQpm-n#DeN>#{DT14U^>eJvJ3PNjsW7S2m?8aM Ikl@*W0RrYbF#rGn delta 468 zcmYjMxlY4C6rA;$*d`%?IOYlokb`hTz}!8*05ymr5`{k?qC_ujmD^Jd>NXHMce9_Npdfh3}eIPGVg^KiqFNk4$Vh*u<7V`s?z({dn(Ek09-2M(Fae?6eX7H z%m6uL*%Rd0=x3#nA1lX5o`^?87bF4$yb1;}#2B@PIXbcj5ukuk=EZ>i1;$z!kF1d8 zvs4(>tZ^fUyT2$%M{eBybEI}0{o5LCOHrr0Z31Otjv!d!tp=!3W>PMw(_INPq+*J| QH2bl|8O$=DlXmBS0p(&YE&u=k diff --git a/SpringBoot-AOP/target/classes/com/fancv/login/BaseUserDTO.class b/SpringBoot-AOP/target/classes/com/fancv/login/BaseUserDTO.class index 24cf52fc54a9934ce12659747c7f418d143d2dd7..13a21545a8ec5cbb53579c09a26ada7b24d811e9 100644 GIT binary patch literal 4411 zcma)8YjYb{8Geqey+~TgvSK@tGi6`~h95v+Cd|N4(vktD@S)7`2l@j@DL;Zzp0m5st}YGvuxH=%p67kf zd*A)Xe{cTv#f(1A*r%yJo|#2h2*12Y$=69p9_0x&B(a(V!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p&j_;kYifpui)#xgwfcHQKH?biw zod{v5o{}jswqMe5N+icwm1`m~Q({><6EoKyU! z_%%l!K#cy5R0@}W36T4^W&&9svTX8~xzC4Kyn_AQQH$sI(%u2ms^A9Pa6Gt5<3)aj z6pj3bj@YUeF!jKq83H1U%nJ^Y)2#de%Fnctf^;cV&a_qLNVQQ`Tb0eW${f!&%37;( zS6gMyG5u?GTeK?Y+9-#08ROaGjjEJrOjbo38T}PX`^<&4&>FSSg8DaV(ZjY7IMUvv z`l2RfD>Y2^1tyDlJqoqSOYKEX%C2mf><>)7furaMvNx9uTu750iK>S!vor9p!QUi0 zY$uJ4T8IzH^N=vhZ;{CxIP_n9!EcsI_eV#5gsR*d{R{f{P&@98{t114Y~&$~U`rys zFvg{%jQ@>nL3xaxyD-NK%0p!8h-^tEBwNx7s>EoI(R&x21+}0hKxRoN$SfHJU4o1V zq!)|?sI!zNsI!zQq$Ma5fzpLc9i-fAo0zRInnp+5=fA@5FyaCHfOk2uDGuh>D3RB} zhvzFykWz3K8<-@eVxG_26e$fAoWV3HUa&ZU_edG|hU0yLR2tv1sop1*!AbgY4Bfi% zFS>N-Pmt$r#6Lqk!S0YuKZC5_8OK>1MLv*WQRpcDf2LVgRzt>_9Q$MgsEs&PD#ZLC@tdKw SP27UZx&NGdgZu0JS^ont-?ae% From e0d8cc33c34f14c73cd43849b5c1a15842d05127 Mon Sep 17 00:00:00 2001 From: Andy Date: Wed, 29 Mar 2023 23:25:04 +0800 Subject: [PATCH 6/6] feature:spring PgSQL --- SpringBoot-PgSQL/pom.xml | 97 +++++++++++++++++++ .../src/main/java/com/fancv/App.java | 17 ++++ .../java/com/fancv/config/DataConfig.java | 43 ++++++++ .../com/fancv/controller/TestController.java | 30 ++++++ .../src/main/resources/application.yaml | 28 ++++++ .../src/test/java/com/fancv/AppTest.java | 20 ++++ 6 files changed, 235 insertions(+) create mode 100644 SpringBoot-PgSQL/pom.xml create mode 100644 SpringBoot-PgSQL/src/main/java/com/fancv/App.java create mode 100644 SpringBoot-PgSQL/src/main/java/com/fancv/config/DataConfig.java create mode 100644 SpringBoot-PgSQL/src/main/java/com/fancv/controller/TestController.java create mode 100644 SpringBoot-PgSQL/src/main/resources/application.yaml create mode 100644 SpringBoot-PgSQL/src/test/java/com/fancv/AppTest.java 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 ); + } +}