From 4e160439b14aa1a68a3c7933437887f143cbcd3b Mon Sep 17 00:00:00 2001 From: gczhang-minhong <1207365364@qq.com> Date: Sun, 15 Dec 2019 21:16:54 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/funtl/spring/boot/service/TbUserService.java | 6 ------ .../spring/{boot => hello}/SpringBootDemoApplication.java | 4 ++-- .../spring/{boot => hello}/controller/HelloController.java | 2 +- .../com/funtl/spring/{boot => hello}/domain/TbUser.java | 2 +- .../funtl/spring/{boot => hello}/mapper/TbUserMapper.java | 4 ++-- .../java/com/funtl/spring/hello/service/TbUserService.java | 6 ++++++ .../{boot => hello}/service/impl/TbUserServiceImpl.java | 6 +++--- .../src/main/resources/mapper/TbUserMapper.xml | 4 ++-- .../boot/SpringBootDemoApplicationTests.java | 7 +++---- 9 files changed, 20 insertions(+), 21 deletions(-) delete mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/boot/service/TbUserService.java rename spring-boot-demo/src/main/java/com/funtl/spring/{boot => hello}/SpringBootDemoApplication.java (79%) rename spring-boot-demo/src/main/java/com/funtl/spring/{boot => hello}/controller/HelloController.java (86%) rename spring-boot-demo/src/main/java/com/funtl/spring/{boot => hello}/domain/TbUser.java (98%) rename spring-boot-demo/src/main/java/com/funtl/spring/{boot => hello}/mapper/TbUserMapper.java (53%) create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/service/TbUserService.java rename spring-boot-demo/src/main/java/com/funtl/spring/{boot => hello}/service/impl/TbUserServiceImpl.java (58%) rename spring-boot-demo/src/test/java/com/{funtl/spring => kmb}/boot/SpringBootDemoApplicationTests.java (95%) diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/boot/service/TbUserService.java b/spring-boot-demo/src/main/java/com/funtl/spring/boot/service/TbUserService.java deleted file mode 100644 index df1097b..0000000 --- a/spring-boot-demo/src/main/java/com/funtl/spring/boot/service/TbUserService.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.funtl.spring.boot.service; - -public interface TbUserService{ - - -} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/boot/SpringBootDemoApplication.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/SpringBootDemoApplication.java similarity index 79% rename from spring-boot-demo/src/main/java/com/funtl/spring/boot/SpringBootDemoApplication.java rename to spring-boot-demo/src/main/java/com/funtl/spring/hello/SpringBootDemoApplication.java index 58492b8..b014b82 100644 --- a/spring-boot-demo/src/main/java/com/funtl/spring/boot/SpringBootDemoApplication.java +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/SpringBootDemoApplication.java @@ -1,11 +1,11 @@ -package com.funtl.spring.boot; +package com.funtl.spring.hello; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import tk.mybatis.spring.annotation.MapperScan; @SpringBootApplication -@MapperScan(basePackages = "com.funtl.spring.boot.mapper") +@MapperScan(basePackages = "com.funtl.spring.hello.mapper") public class SpringBootDemoApplication { public static void main(String[] args) { diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/boot/controller/HelloController.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/controller/HelloController.java similarity index 86% rename from spring-boot-demo/src/main/java/com/funtl/spring/boot/controller/HelloController.java rename to spring-boot-demo/src/main/java/com/funtl/spring/hello/controller/HelloController.java index 42c47db..cc2ac2d 100644 --- a/spring-boot-demo/src/main/java/com/funtl/spring/boot/controller/HelloController.java +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/controller/HelloController.java @@ -1,4 +1,4 @@ -package com.funtl.spring.boot.controller; +package com.funtl.spring.hello.controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/boot/domain/TbUser.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/domain/TbUser.java similarity index 98% rename from spring-boot-demo/src/main/java/com/funtl/spring/boot/domain/TbUser.java rename to spring-boot-demo/src/main/java/com/funtl/spring/hello/domain/TbUser.java index bff2b96..be16d9b 100644 --- a/spring-boot-demo/src/main/java/com/funtl/spring/boot/domain/TbUser.java +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/domain/TbUser.java @@ -1,4 +1,4 @@ -package com.funtl.spring.boot.domain; +package com.funtl.spring.hello.domain; import javax.persistence.Column; import javax.persistence.GeneratedValue; diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/boot/mapper/TbUserMapper.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/mapper/TbUserMapper.java similarity index 53% rename from spring-boot-demo/src/main/java/com/funtl/spring/boot/mapper/TbUserMapper.java rename to spring-boot-demo/src/main/java/com/funtl/spring/hello/mapper/TbUserMapper.java index 7d34aef..a826422 100644 --- a/spring-boot-demo/src/main/java/com/funtl/spring/boot/mapper/TbUserMapper.java +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/mapper/TbUserMapper.java @@ -1,6 +1,6 @@ -package com.funtl.spring.boot.mapper; +package com.funtl.spring.hello.mapper; -import com.funtl.spring.boot.domain.TbUser; +import com.funtl.spring.hello.domain.TbUser; import tk.mybatis.mapper.MyMapper; public interface TbUserMapper extends MyMapper { diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/service/TbUserService.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/service/TbUserService.java new file mode 100644 index 0000000..dc0e523 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/service/TbUserService.java @@ -0,0 +1,6 @@ +package com.funtl.spring.hello.service; + +public interface TbUserService{ + + +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/boot/service/impl/TbUserServiceImpl.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/service/impl/TbUserServiceImpl.java similarity index 58% rename from spring-boot-demo/src/main/java/com/funtl/spring/boot/service/impl/TbUserServiceImpl.java rename to spring-boot-demo/src/main/java/com/funtl/spring/hello/service/impl/TbUserServiceImpl.java index 10c7873..3565b2c 100644 --- a/spring-boot-demo/src/main/java/com/funtl/spring/boot/service/impl/TbUserServiceImpl.java +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/service/impl/TbUserServiceImpl.java @@ -1,7 +1,7 @@ -package com.funtl.spring.boot.service.impl; +package com.funtl.spring.hello.service.impl; -import com.funtl.spring.boot.mapper.TbUserMapper; -import com.funtl.spring.boot.service.TbUserService; +import com.funtl.spring.hello.mapper.TbUserMapper; +import com.funtl.spring.hello.service.TbUserService; import org.springframework.stereotype.Service; import javax.annotation.Resource; diff --git a/spring-boot-demo/src/main/resources/mapper/TbUserMapper.xml b/spring-boot-demo/src/main/resources/mapper/TbUserMapper.xml index 33b1025..96caa95 100644 --- a/spring-boot-demo/src/main/resources/mapper/TbUserMapper.xml +++ b/spring-boot-demo/src/main/resources/mapper/TbUserMapper.xml @@ -1,7 +1,7 @@ - - + + diff --git a/spring-boot-demo/src/test/java/com/funtl/spring/boot/SpringBootDemoApplicationTests.java b/spring-boot-demo/src/test/java/com/kmb/boot/SpringBootDemoApplicationTests.java similarity index 95% rename from spring-boot-demo/src/test/java/com/funtl/spring/boot/SpringBootDemoApplicationTests.java rename to spring-boot-demo/src/test/java/com/kmb/boot/SpringBootDemoApplicationTests.java index f64f3d8..f6aaadf 100644 --- a/spring-boot-demo/src/test/java/com/funtl/spring/boot/SpringBootDemoApplicationTests.java +++ b/spring-boot-demo/src/test/java/com/kmb/boot/SpringBootDemoApplicationTests.java @@ -1,7 +1,7 @@ -package com.funtl.spring.boot; +package com.kmb.boot; -import com.funtl.spring.boot.domain.TbUser; -import com.funtl.spring.boot.mapper.TbUserMapper; +import com.funtl.spring.hello.domain.TbUser; +import com.funtl.spring.hello.mapper.TbUserMapper; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import org.junit.Test; @@ -94,7 +94,6 @@ public void testDelete() { public void testPage() { Example example = new Example(TbUser.class); example.createCriteria().andLike("username", "z%"); - PageHelper.startPage(1, 5); PageInfo pageInfo = new PageInfo<>(tbUserMapper.selectByExample(example)); System.out.println(pageInfo.getTotal()); From 54379d906a6dc724621a4491e9e00753340a1e21 Mon Sep 17 00:00:00 2001 From: gczhang-minhong <1207365364@qq.com> Date: Sat, 11 Jan 2020 00:51:39 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hello/moudule/Prototype/CloneTest.java | 48 +++++++ .../moudule/Prototype/CloneableTarget.java | 21 +++ .../moudule/Prototype/DeepCloneTest.java | 37 +++++ .../Prototype/DeepCloneableTarget.java | 30 ++++ .../moudule/Prototype/DeepPrototype.java | 72 ++++++++++ .../hello/moudule/Prototype/Prototype.java | 34 +++++ .../IGiftInfoStrategyService.java | 4 + .../hello/moudule/adapter/AdapterTest.java | 33 +++++ .../adapter/ClassSiginForWebChatAdapter.java | 29 ++++ .../adapter/ISiginForThirdService.java | 25 ++++ .../moudule/adapter/ISiginForWebChat.java | 19 +++ .../hello/moudule/adapter/ISiginSerevice.java | 6 + .../adapter/LoginForTelphoneAdapter.java | 19 +++ .../adapter/ObjectSiginForWebChatAdapter.java | 22 +++ .../hello/moudule/adapter/ResultMsg.java | 41 ++++++ .../moudule/adapter/SiginForThirdAdapter.java | 38 +++++ .../hello/moudule/adapter/SiginService.java | 22 +++ .../decorator/ISiginForThirdService.java | 28 ++++ .../moudule/decorator/ISiginSerevice.java | 10 ++ .../decorator/SiginForThirdService.java | 39 +++++ .../hello/moudule/decorator/SiginService.java | 24 ++++ .../hello/moudule/decorator/SiginTest.java | 33 +++++ .../spring/hello/moudule/excuter/Boss.java | 21 +++ .../hello/moudule/excuter/ExcuterA.java | 18 +++ .../hello/moudule/excuter/ExcuterB.java | 17 +++ .../hello/moudule/excuter/IExcuter.java | 6 + .../spring/hello/moudule/excuter/Leader.java | 26 ++++ .../hello/moudule/excuter/MemberAction.java | 16 +++ .../moudule/excuter/SelvletDispatcher.java | 111 +++++++++++++++ .../moudule/factory/AbstractFactory.java | 30 ++++ .../moudule/factory/AbstractFactoryTest.java | 26 ++++ .../hello/moudule/factory/AudiFactory.java | 20 +++ .../hello/moudule/factory/BenzFactory.java | 20 +++ .../hello/moudule/factory/BmwFactory.java | 20 +++ .../hello/moudule/factory/CarFactory.java | 30 ++++ .../spring/hello/moudule/factory/Factory.java | 7 + .../hello/moudule/factory/FactoryTest.java | 25 ++++ .../hello/moudule/observer/demo1/Message.java | 38 +++++ .../observer/demo1/MessageObserver.java | 30 ++++ .../demo1/MessagePublishObservable.java | 51 +++++++ .../hello/moudule/observer/demo1/Test.java | 38 +++++ .../hello/moudule/observer/demo2/Event.java | 87 ++++++++++++ .../moudule/observer/demo2/EventListener.java | 56 ++++++++ .../hello/moudule/observer/demo2/Mouse.java | 33 +++++ .../observer/demo2/MouseEventCallback.java | 29 ++++ .../observer/demo2/MouseEventType.java | 9 ++ .../moudule/observer/demo2/MouseTest.java | 30 ++++ .../moudule/observer/demo3/OrderEvent.java | 18 +++ .../moudule/observer/demo3/OrderPublish.java | 33 +++++ .../moudule/observer/demo3/OrderService.java | 35 +++++ .../moudule/observer/demo3/SmsListener.java | 26 ++++ .../funtl/spring/hello/moudule/proxy/Man.java | 18 +++ .../spring/hello/moudule/proxy/Person.java | 6 + .../spring/hello/moudule/proxy/Test.java | 44 ++++++ .../hello/moudule/proxy/cglibproxy/CgMan.java | 16 +++ .../moudule/proxy/cglibproxy/CgMeiPo.java | 46 ++++++ .../moudule/proxy/cglibproxy/CgTest.java | 18 +++ .../hello/moudule/proxy/jdkProxy/MeiPo.java | 40 ++++++ .../proxy/proxyDefine/CuClassLoader.java | 29 ++++ .../moudule/proxy/proxyDefine/CuMan.java | 17 +++ .../moudule/proxy/proxyDefine/CuMeipo.java | 38 +++++ .../moudule/proxy/proxyDefine/CuPerson.java | 6 + .../moudule/proxy/proxyDefine/CuProxy.java | 44 ++++++ .../moudule/proxy/proxyDefine/CuTest.java | 22 +++ .../proxy/staticProxy/StaticProxy.java | 32 +++++ .../hello/moudule/simpleFactory/Audi.java | 17 +++ .../hello/moudule/simpleFactory/Benz.java | 17 +++ .../hello/moudule/simpleFactory/Bmw.java | 17 +++ .../hello/moudule/simpleFactory/Car.java | 5 + .../moudule/simpleFactory/SimpleFactory.java | 25 ++++ .../hello/moudule/singleton/BeanFactory.java | 34 +++++ .../hello/moudule/singleton/Hungry.java | 28 ++++ .../hello/moudule/singleton/LazyFour.java | 30 ++++ .../hello/moudule/singleton/LazyOne.java | 28 ++++ .../hello/moudule/singleton/LazyThree.java | 43 ++++++ .../hello/moudule/singleton/LazyTwo.java | 23 +++ .../moudule/singleton/enumSingleton.java | 24 ++++ .../hello/moudule/strategy/demo1/AliPay.java | 19 +++ .../hello/moudule/strategy/demo1/Order.java | 26 ++++ .../moudule/strategy/demo1/PayState.java | 38 +++++ .../hello/moudule/strategy/demo1/PayType.java | 17 +++ .../hello/moudule/strategy/demo1/Payment.java | 11 ++ .../moudule/strategy/demo1/StrategyTest.java | 20 +++ .../moudule/strategy/demo1/UnionPay.java | 19 +++ .../moudule/strategy/demo1/WechatPay.java | 19 +++ .../moudule/strategy/demo2/Calculator.java | 8 ++ .../hello/moudule/strategy/demo2/Context.java | 28 ++++ .../moudule/strategy/demo2/OptionAdd.java | 19 +++ .../moudule/strategy/demo2/OptionDivide.java | 17 +++ .../strategy/demo2/OptionMultiply.java | 18 +++ .../strategy/demo2/OptionSubstract.java | 18 +++ .../hello/moudule/strategy/demo2/Test.java | 33 +++++ .../hello/moudule/template/JdbcTemplate.java | 133 ++++++++++++++++++ .../spring/hello/moudule/template/Merber.java | 59 ++++++++ .../hello/moudule/template/MerberDao.java | 35 +++++ .../hello/moudule/template/RowMapper.java | 8 ++ .../hello/moudule/template/TemplateTest.java | 17 +++ 97 files changed, 2769 insertions(+) create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/Prototype/CloneTest.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/Prototype/CloneableTarget.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/Prototype/DeepCloneTest.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/Prototype/DeepCloneableTarget.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/Prototype/DeepPrototype.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/Prototype/Prototype.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/StrategySpring/IGiftInfoStrategyService.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/AdapterTest.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/ClassSiginForWebChatAdapter.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/ISiginForThirdService.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/ISiginForWebChat.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/ISiginSerevice.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/LoginForTelphoneAdapter.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/ObjectSiginForWebChatAdapter.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/ResultMsg.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/SiginForThirdAdapter.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/SiginService.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/decorator/ISiginForThirdService.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/decorator/ISiginSerevice.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/decorator/SiginForThirdService.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/decorator/SiginService.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/decorator/SiginTest.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/excuter/Boss.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/excuter/ExcuterA.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/excuter/ExcuterB.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/excuter/IExcuter.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/excuter/Leader.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/excuter/MemberAction.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/excuter/SelvletDispatcher.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/AbstractFactory.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/AbstractFactoryTest.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/AudiFactory.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/BenzFactory.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/BmwFactory.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/CarFactory.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/Factory.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/FactoryTest.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo1/Message.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo1/MessageObserver.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo1/MessagePublishObservable.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo1/Test.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo2/Event.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo2/EventListener.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo2/Mouse.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo2/MouseEventCallback.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo2/MouseEventType.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo2/MouseTest.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo3/OrderEvent.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo3/OrderPublish.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo3/OrderService.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo3/SmsListener.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/Man.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/Person.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/Test.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/cglibproxy/CgMan.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/cglibproxy/CgMeiPo.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/cglibproxy/CgTest.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/jdkProxy/MeiPo.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/proxyDefine/CuClassLoader.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/proxyDefine/CuMan.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/proxyDefine/CuMeipo.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/proxyDefine/CuPerson.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/proxyDefine/CuProxy.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/proxyDefine/CuTest.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/staticProxy/StaticProxy.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/simpleFactory/Audi.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/simpleFactory/Benz.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/simpleFactory/Bmw.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/simpleFactory/Car.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/simpleFactory/SimpleFactory.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/singleton/BeanFactory.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/singleton/Hungry.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/singleton/LazyFour.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/singleton/LazyOne.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/singleton/LazyThree.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/singleton/LazyTwo.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/singleton/enumSingleton.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/AliPay.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/Order.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/PayState.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/PayType.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/Payment.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/StrategyTest.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/UnionPay.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/WechatPay.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo2/Calculator.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo2/Context.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo2/OptionAdd.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo2/OptionDivide.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo2/OptionMultiply.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo2/OptionSubstract.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo2/Test.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/template/JdbcTemplate.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/template/Merber.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/template/MerberDao.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/template/RowMapper.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/template/TemplateTest.java diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/Prototype/CloneTest.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/Prototype/CloneTest.java new file mode 100644 index 0000000..38a2b60 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/Prototype/CloneTest.java @@ -0,0 +1,48 @@ +package com.funtl.spring.hello.moudule.Prototype; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.Prototype + * @ClassName: CloneTest + * @Author: Administrator + * Date: 2020/1/1 0001 17:16 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 浅度克隆对象的测试 + */ +public class CloneTest { + /** + * 原型模式就是从一个对象再创建另外一个可定制的对象, 而且不需要知道任何创建的细节。 + * 所谓原型模式, 就是 Java 中的克隆技术, 以某个对象为原型。 复制出新的对象。 显然新的对象具备原型对象的特点, 效率高(避免了重新执行构造过程步骤) + * @param args + */ + public static void main(String[] args) { + Prototype p = new Prototype(); + p.name="kang"; + p.cloneableTarget = new CloneableTarget("clone","CloneableTarget"); + System.out.println("原有的对象:"+p); + System.out.println("原有的值对象引用:"+p.name.hashCode()); + System.out.println("原有的引用类型对象:"+p.cloneableTarget); + try { + //方式一 :通过重写clone()方法进行浅拷贝 + Prototype clonePrototype = (Prototype) p.clone(); + System.out.println("重写clone()克隆的对象:"+clonePrototype); + System.out.println("重写clone()克隆的值对象引用:"+p.name.hashCode()); + System.out.println("重写clone()克隆的引用类型对象:"+ clonePrototype.cloneableTarget); + + //通过修改引用对象String类型的值,发现原有的对象的值没有发生改变,因为String对象是不可变对象,放在常量池中的,无法修改的 + //String 可以比较特殊,可以看做是值传递 + clonePrototype.name ="sun"; + System.out.println("原有对象的name:"+p.name); + System.out.println("修改过的clone对象的name:"+clonePrototype.name); + + //方式二: 通过拷贝构造方法实现浅拷贝 + Prototype constructClone= new Prototype(p); + System.out.println("构造方法克隆的对象:"+constructClone); + System.out.println("构造方法克隆的值对象引用:"+constructClone.name.hashCode()); + System.out.println("构造方法克隆的引用类型对象:"+ constructClone.cloneableTarget); + } catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + } +} + diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/Prototype/CloneableTarget.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/Prototype/CloneableTarget.java new file mode 100644 index 0000000..c87d65f --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/Prototype/CloneableTarget.java @@ -0,0 +1,21 @@ +package com.funtl.spring.hello.moudule.Prototype; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.Prototype + * @ClassName: CloneableTarget + * @Author: Administrator + * Date: 2020/1/1 0001 17:15 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 浅度克隆目标的引用对象 + */ +public class CloneableTarget { + public String cloneName; + + public String cloneClass; + + public CloneableTarget( String cloneName,String cloneClass) { + this.cloneName = cloneName; + this.cloneClass = cloneClass; + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/Prototype/DeepCloneTest.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/Prototype/DeepCloneTest.java new file mode 100644 index 0000000..3db06f1 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/Prototype/DeepCloneTest.java @@ -0,0 +1,37 @@ +package com.funtl.spring.hello.moudule.Prototype; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.Prototype + * @ClassName: DeepCloneTest + * @Author: Administrator + * Date: 2020/1/1 0001 17:21 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 深度拷贝的测试 + */ +public class DeepCloneTest { + public static void main(String[] args) { + DeepPrototype p = new DeepPrototype(); + p.name="kang"; + p.deepCloneableTarget = new DeepCloneableTarget("clone","CloneableTarget"); + System.out.println("原有的对象:"+p); + System.out.println("原有的值对象引用:"+p.name.hashCode()); + System.out.println("原有的引用类型对象:"+p.deepCloneableTarget); + + try { + //方式一 :通过重写clone()方法进行浅拷贝 + DeepPrototype clonePrototype = (DeepPrototype) p.clone(); + System.out.println("clone()方法克隆的对象:"+clonePrototype); + System.out.println("clone()方法克隆的值对象引用:"+p.name.hashCode()); + System.out.println("clone()方法克隆的引用类型对象:"+ clonePrototype.deepCloneableTarget); + + //方式二: 通过对象序列化实现深拷贝 + DeepPrototype serializableClone= (DeepPrototype) p.deepClone(); + System.out.println("序列化方法克隆的对象:"+serializableClone); + System.out.println("构序列化方法克隆的值对象引用:"+serializableClone.name.hashCode()); + System.out.println("序列化方法克隆的引用类型对象:"+ serializableClone.deepCloneableTarget); + } catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/Prototype/DeepCloneableTarget.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/Prototype/DeepCloneableTarget.java new file mode 100644 index 0000000..895b733 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/Prototype/DeepCloneableTarget.java @@ -0,0 +1,30 @@ +package com.funtl.spring.hello.moudule.Prototype; + +import java.io.Serializable; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.Prototype + * @ClassName: DeepCloneableTarget + * @Author: Administrator + * Date: 2020/1/1 0001 17:20 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 深度拷贝的目标引用对象 + */ +public class DeepCloneableTarget implements Serializable,Cloneable { + + private String cloneName; + + private String cloneClass; + + + public DeepCloneableTarget(String cloneName, String cloneClass) { + this.cloneName = cloneName; + this.cloneClass = cloneClass; + } + + @Override + protected Object clone() throws CloneNotSupportedException { + return super.clone(); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/Prototype/DeepPrototype.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/Prototype/DeepPrototype.java new file mode 100644 index 0000000..fa23627 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/Prototype/DeepPrototype.java @@ -0,0 +1,72 @@ +package com.funtl.spring.hello.moudule.Prototype; + +import java.io.*; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.Prototype + * @ClassName: DeepPrototype + * @Author: Administrator + * Date: 2020/1/1 0001 17:20 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 深度拷贝的实现拷贝的两种方式 + */ +public class DeepPrototype implements Serializable,Cloneable { + + public String name ; + + public DeepCloneableTarget deepCloneableTarget; + + public DeepPrototype(){ + + } + //方式1 :通过重写clone方法来实现深拷贝 (引用对象多,这种方法比较繁琐) + @Override + protected Object clone() throws CloneNotSupportedException { + Object deep = null; + try { + deep = super.clone(); + } catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + DeepPrototype deepPrototype = (DeepPrototype) deep; + deepPrototype.deepCloneableTarget = (DeepCloneableTarget) deepPrototype.deepCloneableTarget.clone(); + return deepPrototype; + } + + //方式2: 通过对象序列化实现深拷贝 (推荐) + public Object deepClone(){ + ByteArrayOutputStream bos = null; + ObjectOutputStream oos = null; + try { + bos = new ByteArrayOutputStream(); + oos = new ObjectOutputStream(bos); + oos.writeObject(this); + + ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); + ObjectInputStream ois = new ObjectInputStream(bis); + return ois.readObject(); + } catch (IOException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + }finally { + if(oos !=null){ + try { + oos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if(bos !=null){ + try { + bos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + //输入流关闭省略 + } + return null; + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/Prototype/Prototype.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/Prototype/Prototype.java new file mode 100644 index 0000000..ccc239c --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/Prototype/Prototype.java @@ -0,0 +1,34 @@ +package com.funtl.spring.hello.moudule.Prototype; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.Prototype + * @ClassName: Prototype + * @Author: Administrator + * Date: 2020/1/1 0001 17:15 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 克隆对象的浅拷贝 + * * 1.通过构造方法来实现浅度拷贝 + * * 2.通过clone()方法来实现浅度拷贝 + */ +public class Prototype implements Cloneable { + + public String name ; + + //拷贝的引用类型的成员变量 + public CloneableTarget cloneableTarget; + + public Prototype(){ + + } + //1.通过构造方法来实现浅度拷贝 + public Prototype(Prototype prototype) { + this.name = prototype.name; + this.cloneableTarget = prototype.cloneableTarget; + } + //2.通过clone()方法来实现浅度拷贝 + @Override + protected Object clone() throws CloneNotSupportedException { + return super.clone(); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/StrategySpring/IGiftInfoStrategyService.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/StrategySpring/IGiftInfoStrategyService.java new file mode 100644 index 0000000..f6b8e26 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/StrategySpring/IGiftInfoStrategyService.java @@ -0,0 +1,4 @@ +package com.funtl.spring.hello.moudule.StrategySpring; + +public interface IGiftInfoStrategyService { +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/AdapterTest.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/AdapterTest.java new file mode 100644 index 0000000..557e9c1 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/AdapterTest.java @@ -0,0 +1,33 @@ +package com.funtl.spring.hello.moudule.adapter; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.adapter + * @ClassName: AdapterTest + * @Author: Administrator + * Date: 2020/1/1 0001 18:47 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +public class AdapterTest { + public static void main(String[] args) { + //需要适配的类,要把 ISiginSerevice 变成 ISiginForWebChat + ISiginSerevice siginSerevice = new SiginService(); + ISiginForWebChat siginForThreadService = new ObjectSiginForWebChatAdapter(siginSerevice); + + //对象适配器 ,传的是一个适配的类,通过组合的方式 + ResultMsg resultMsg = siginForThreadService.loginForWechat("1231321ffasfasffad"); + System.out.println(resultMsg.getMsg()); + + //类适配器,通过继承实现的 + ResultMsg msg = new ClassSiginForWebChatAdapter().loginForWechat("1231321ffasfasffad"); + System.out.println(msg.getMsg()); + + //接口适配器 ,主要实现了一个抽象的适配器 + //但是接口中有太多方法,我们要使用时必须实现接口并实现其中的所有方法,可以使用抽象类来实现接口 + //并不对方法进行实现(仅置空),然后我们再继承这个抽象类来通过重写想用的方法的方式来实现。这个抽象类就是适配器 + ISiginForThirdService siginForWebChat = new LoginForTelphoneAdapter(); + ResultMsg telPoneMsg = siginForWebChat.loginForTelphone("13588304966","1234"); + System.out.println(telPoneMsg.getMsg()); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/ClassSiginForWebChatAdapter.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/ClassSiginForWebChatAdapter.java new file mode 100644 index 0000000..25e5722 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/ClassSiginForWebChatAdapter.java @@ -0,0 +1,29 @@ +package com.funtl.spring.hello.moudule.adapter; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.adapter + * @ClassName: ClassSiginForWebChatAdapter + * @Author: Administrator + * Date: 2020/1/1 0001 18:39 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 类适配器 目标接口为ISiginForWebChat,但是适配者的接口为ISiginService + * 通过把普通登录的接口转换成微信登录的接口 + */ +public class ClassSiginForWebChatAdapter extends SiginService implements ISiginForWebChat{ + /** + * 原理:通过继承来实现适配器功能。 + * 当我们要访问的接口A中没有我们想要的方法 , + * 却在另一个接口B中发现了合适的方法,我们又不能改变访问接口A, + * 在这种情况下,我们可以定义一个适配器p来进行中转,这个适配器p要实现我们访问的接口A, + * 这样我们就能继续访问当前接口A中的方法(虽然它目前不是我们的菜), + * 然后再继承接口B的实现类,这样我们可以在适配器P中访问接口B的方法了, + * 这时我们在适配器P中的接口A方法中直接引用B中的合适方法,这样就完成了一个简单的类适配器。 + * @param openId + * @return + */ + @Override + public ResultMsg loginForWechat(String openId) { + return login(openId,null); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/ISiginForThirdService.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/ISiginForThirdService.java new file mode 100644 index 0000000..fc6ce06 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/ISiginForThirdService.java @@ -0,0 +1,25 @@ +package com.funtl.spring.hello.moudule.adapter; + +//第三方登录的接口 +public interface ISiginForThirdService { + /** + * 通过qq登录 + * @param openId + * @return + */ + ResultMsg loginForQQ(String openId); + /** + * 通过微信登录 + * @param openId + * @return + */ + ResultMsg loginForWechat(String openId); + + /** + * 通过手机号和验证码登录 + * @param telphone + * @param code + * @return + */ + ResultMsg loginForTelphone(String telphone,String code); +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/ISiginForWebChat.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/ISiginForWebChat.java new file mode 100644 index 0000000..f9adbc9 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/ISiginForWebChat.java @@ -0,0 +1,19 @@ +package com.funtl.spring.hello.moudule.adapter; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.adapter + * @ClassName: ISiginForWebChat + * @Author: Administrator + * Date: 2020/1/1 0001 18:38 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 通过微信接口登录 + */ +public interface ISiginForWebChat { + /** + * 通过微信登录 + * @param openId + * @return + */ + ResultMsg loginForWechat(String openId); +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/ISiginSerevice.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/ISiginSerevice.java new file mode 100644 index 0000000..2a95bc0 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/ISiginSerevice.java @@ -0,0 +1,6 @@ +package com.funtl.spring.hello.moudule.adapter; + +//登录的接口业务 +public interface ISiginSerevice { + ResultMsg login(String username,String password); +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/LoginForTelphoneAdapter.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/LoginForTelphoneAdapter.java new file mode 100644 index 0000000..40824b3 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/LoginForTelphoneAdapter.java @@ -0,0 +1,19 @@ +package com.funtl.spring.hello.moudule.adapter; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.adapter + * @ClassName: LoginForTelphoneAdapter + * @Author: Administrator + * Date: 2020/1/1 0001 18:46 + * project name: spring-boot-alibaba-samples + * @Version: 通过电话号码和动态密码登录,只需要重写对应的方法接口 + * @Description: 只需要用电话号码登录 + */ +public class LoginForTelphoneAdapter extends SiginForThirdAdapter { + public ResultMsg loginForTelphone(String telphone, String code) { + System.out.println("通过电话号码登录"); + ResultMsg msg = new ResultMsg("200","qq登录成功",new Object()); + System.out.println("登录的结果为"+msg.getMsg()); + return msg; + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/ObjectSiginForWebChatAdapter.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/ObjectSiginForWebChatAdapter.java new file mode 100644 index 0000000..58e1e20 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/ObjectSiginForWebChatAdapter.java @@ -0,0 +1,22 @@ +package com.funtl.spring.hello.moudule.adapter; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.adapter + * @ClassName: ObjectSiginForWebChatAdapter + * @Author: Administrator + * Date: 2020/1/1 0001 18:43 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 对象适配器模式 默认通过组合来实现的 + */ +public class ObjectSiginForWebChatAdapter implements ISiginForWebChat { + private ISiginSerevice siginSerevice; + + public ObjectSiginForWebChatAdapter(ISiginSerevice siginSerevice) { + this.siginSerevice = siginSerevice; + } + @Override + public ResultMsg loginForWechat(String openId) { + return siginSerevice.login(openId,null); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/ResultMsg.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/ResultMsg.java new file mode 100644 index 0000000..5ba5747 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/ResultMsg.java @@ -0,0 +1,41 @@ +package com.funtl.spring.hello.moudule.adapter; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.adapter + * @ClassName: ResultMsg + * @Author: Administrator + * Date: 2020/1/1 0001 18:37 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 登录返回的结果的类 + */ +public class ResultMsg { + private String code; + private String msg; + private Object data; + + public ResultMsg(String code, String msg, Object data) { + this.code = code; + this.msg = msg; + this.data = data; + } + + public String getCode() { + return code; + } + public void setCode(String code) { + this.code = code; + } + public String getMsg() { + return msg; + } + public void setMsg(String msg) { + this.msg = msg; + } + public Object getData() { + return data; + } + public void setData(Object data) { + this.data = data; + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/SiginForThirdAdapter.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/SiginForThirdAdapter.java new file mode 100644 index 0000000..714abaa --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/SiginForThirdAdapter.java @@ -0,0 +1,38 @@ +package com.funtl.spring.hello.moudule.adapter; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.adapter + * @ClassName: SiginForThirdAdapter + * @Author: Administrator + * Date: 2020/1/1 0001 18:45 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 抽象适配器 因为接口太多,所以用了一个抽象的类的适配器,来默认实现 + */ +public class SiginForThirdAdapter implements ISiginForThirdService { + /** + * 通过抽象类来实现适配,这种适配稍别于上面所述的适配。 + * 当存在这样一个接口,其中定义了N多的方法, + * 而我们现在却只想使用其中的一个到几个方法, + * 如果我们直接实现接口,那么我们要对所有的方法进行实现, + * 哪怕我们仅仅是对不需要的方法进行置空(只写一对大括号,不做具体方法实现)也会导致这个类变得臃肿, + * 调用也不方便,这时我们可以使用一个抽象类作为中间件,即适配器, + * 用这个抽象类实现接口,而在抽象类中所有的方法都进行置空, + * 那么我们在创建抽象类的继承类,而且重写我们需要使用的那几个方法即可。 + * @param openId + * @return + */ + @Override + public ResultMsg loginForQQ(String openId) { + return new ResultMsg("200","qq登录成功",new Object()); + } + + @Override + public ResultMsg loginForWechat(String openId) { + return new ResultMsg("200","微信登录成功",new Object()); + } + @Override + public ResultMsg loginForTelphone(String telphone, String code) { + return new ResultMsg("200","手机登录成功",new Object()); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/SiginService.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/SiginService.java new file mode 100644 index 0000000..02897af --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/adapter/SiginService.java @@ -0,0 +1,22 @@ +package com.funtl.spring.hello.moudule.adapter; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.adapter + * @ClassName: SiginService + * @Author: Administrator + * Date: 2020/1/1 0001 18:38 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 登录的具体实现 + */ +public class SiginService implements ISiginSerevice { + /** + * 登录的方法 + * @param username + * @param password + * @return + */ + public ResultMsg login(String username,String password){ + return new ResultMsg("200","登录成功",new Object()); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/decorator/ISiginForThirdService.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/decorator/ISiginForThirdService.java new file mode 100644 index 0000000..bc1460d --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/decorator/ISiginForThirdService.java @@ -0,0 +1,28 @@ +package com.funtl.spring.hello.moudule.decorator; + +import com.funtl.spring.hello.moudule.adapter.ResultMsg; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.decorator + * @ClassName: ISiginForThirdService + * @Author: Administrator + * Date: 2020/1/1 0001 18:57 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 装饰角色 拓展了发送短信的功能 + */ +public interface ISiginForThirdService extends ISiginSerevice { + /** + * 原有登录的方法 + * @param username + * @param password + * @return + */ + ResultMsg login(String username, String password); + /** + * 发送短信 + * @param msg + * @return + */ + ResultMsg sendShortMessage(String msg); +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/decorator/ISiginSerevice.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/decorator/ISiginSerevice.java new file mode 100644 index 0000000..db7907e --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/decorator/ISiginSerevice.java @@ -0,0 +1,10 @@ +package com.funtl.spring.hello.moudule.decorator; + +import com.funtl.spring.hello.moudule.adapter.ResultMsg; + +/** + * 抽象构件角色 登录的接口业务 + */ +public interface ISiginSerevice { + ResultMsg login(String username, String password); +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/decorator/SiginForThirdService.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/decorator/SiginForThirdService.java new file mode 100644 index 0000000..6bde3cf --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/decorator/SiginForThirdService.java @@ -0,0 +1,39 @@ +package com.funtl.spring.hello.moudule.decorator; + +import com.funtl.spring.hello.moudule.adapter.ResultMsg; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.decorator + * @ClassName: SiginForThirdService + * @Author: Administrator + * Date: 2020/1/1 0001 18:58 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 具体的装饰角色 原有的登录功能增加了发送短信的功能 + */ +public class SiginForThirdService implements ISiginForThirdService { + private ISiginSerevice siginSerevice ; + public SiginForThirdService(ISiginSerevice siginSerevice) { + this.siginSerevice = siginSerevice; + } + @Override + public ResultMsg login(String username, String password) { + ResultMsg msg = siginSerevice.login(username,password); + //注册成功发送短信的功能 + if(msg.getCode().equals("200")){ + System.out.println("用户登录成功"); + msg = sendShortMessage(username); + } + return msg; + } + /** + * 发送短信的功能 这个是装饰器 增加的额外的功能,在登录成功之后发送短信通知 + * @param username + * @return + */ + @Override + public ResultMsg sendShortMessage(String username) { + System.out.println("恭喜用户:"+username+"发送短信成功"); + return new ResultMsg("200","发送短信成功",new Object()); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/decorator/SiginService.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/decorator/SiginService.java new file mode 100644 index 0000000..e926bb3 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/decorator/SiginService.java @@ -0,0 +1,24 @@ +package com.funtl.spring.hello.moudule.decorator; + +import com.funtl.spring.hello.moudule.adapter.ResultMsg; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.decorator + * @ClassName: SiginService + * @Author: Administrator + * Date: 2020/1/1 0001 18:57 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 具体构件角色 登录的具体实现 + */ +public class SiginService implements ISiginSerevice { + /** + * 登录的方法 + * @param username + * @param password + * @return + */ + public ResultMsg login(String username, String password){ + return new ResultMsg("200","登录成功",new Object()); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/decorator/SiginTest.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/decorator/SiginTest.java new file mode 100644 index 0000000..e018463 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/decorator/SiginTest.java @@ -0,0 +1,33 @@ +package com.funtl.spring.hello.moudule.decorator; + +/** + * 在spring中的引用: Spring 的 ApplicationContext 中配置所有的 DataSource。 + * 这些 DataSource 可能是各种不同类型的, 比如不同的数据库: Oracle、 SQL Server、 MySQL 等, 也可能是不同的数据源: + * 比如Apache 提 供 的 org.apache.commons.dbcp.BasicDataSource 、 + * Spring 提 供 的org.springframework.jndi.JndiObjectFactoryBean 等。 + * 然后 SessionFactory 根据客户的每次请求, 将 DataSource 属性设置成不同的数据源, 以到达切换数据源的目的。 + */ +public class SiginTest { + + /** + * 装饰者测试 + * 在装饰模式中的角色有: + * + * 抽象构件(Component)角色:给出一个抽象接口,以规范准备接收附加责任的对象。 + * + * 具体构件(ConcreteComponent)角色:定义一个将要接收附加责任的类。 + * + * 装饰(Decorator)角色:持有一个构件(Component)对象的实例,并定义一个与抽象构件接口一致的接口。 + * + * 具体装饰(ConcreteDecorator)角色:负责给构件对象“贴上”附加的责任。 + * @param args + */ + public static void main(String[] args) { + + ISiginSerevice siginSerevice = new SiginService(); + + ISiginSerevice siginForThirdService = new SiginForThirdService(siginSerevice); + + siginForThirdService.login("sunkang","4324"); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/excuter/Boss.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/excuter/Boss.java new file mode 100644 index 0000000..4d6137b --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/excuter/Boss.java @@ -0,0 +1,21 @@ +package com.funtl.spring.hello.moudule.excuter; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.excuter + * @ClassName: Boss + * @Author: Administrator + * Date: 2020/1/1 0001 18:30 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +public class Boss { + public static void main(String[] args) { + Leader leader = new Leader(); + //看上去好像是我们的项目经理在干活 + //但实际干活的人是普通员工 + //这就是典型,干活是我的,功劳是你的 + leader.excute("登录"); + leader.excute("加密"); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/excuter/ExcuterA.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/excuter/ExcuterA.java new file mode 100644 index 0000000..dffdaec --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/excuter/ExcuterA.java @@ -0,0 +1,18 @@ +package com.funtl.spring.hello.moudule.excuter; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.excuter + * @ClassName: ExcuterA + * @Author: Administrator + * Date: 2020/1/1 0001 18:29 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 员工A执行某项命令 + */ +public class ExcuterA implements IExcuter{ + + @Override + public void excute(String command) { + System.out.println("员工A 开始做"+command+"的工作"); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/excuter/ExcuterB.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/excuter/ExcuterB.java new file mode 100644 index 0000000..55cac0a --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/excuter/ExcuterB.java @@ -0,0 +1,17 @@ +package com.funtl.spring.hello.moudule.excuter; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.excuter + * @ClassName: ExcuterB + * @Author: Administrator + * Date: 2020/1/1 0001 18:29 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +public class ExcuterB implements IExcuter{ + @Override + public void excute(String command) { + System.out.println("员工B 开始做"+command+"的工作"); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/excuter/IExcuter.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/excuter/IExcuter.java new file mode 100644 index 0000000..8887b46 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/excuter/IExcuter.java @@ -0,0 +1,6 @@ +package com.funtl.spring.hello.moudule.excuter; + +//执行的接口 +public interface IExcuter { + void excute(String command); +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/excuter/Leader.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/excuter/Leader.java new file mode 100644 index 0000000..f328046 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/excuter/Leader.java @@ -0,0 +1,26 @@ +package com.funtl.spring.hello.moudule.excuter; + +import java.util.HashMap; +import java.util.Map; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.excuter + * @ClassName: Leader + * @Author: Administrator + * Date: 2020/1/1 0001 18:30 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: leader 委派者 任务分发的作用 + */ +public class Leader implements IExcuter { + + private Map targets = new HashMap(); + public Leader() { + targets.put("加密",new ExcuterA()); + targets.put("登录",new ExcuterB()); + } + @Override + public void excute(String command) { + targets.get(command).excute(command); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/excuter/MemberAction.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/excuter/MemberAction.java new file mode 100644 index 0000000..cf28e60 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/excuter/MemberAction.java @@ -0,0 +1,16 @@ +package com.funtl.spring.hello.moudule.excuter; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.excuter + * @ClassName: MemberAction + * @Author: Administrator + * Date: 2020/1/1 0001 18:31 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 模拟controller层 + */ +public class MemberAction { + public void getMemberById(String mid){ + + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/excuter/SelvletDispatcher.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/excuter/SelvletDispatcher.java new file mode 100644 index 0000000..cd7e19f --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/excuter/SelvletDispatcher.java @@ -0,0 +1,111 @@ +package com.funtl.spring.hello.moudule.excuter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.excuter + * @ClassName: SelvletDispatcher + * @Author: Administrator + * Date: 2020/1/1 0001 18:31 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 委派模式的实现mvc的简单实例 + * selvelt的任务分发者 ,主要完成url的映射和调用 + */ +public class SelvletDispatcher { + //这里也可以用map 对象来保存Hanlder对象 + private List handlerMapping = new ArrayList(); + + public SelvletDispatcher() { + //简单实现一个controller的映射 + try { + Class clazz = MemberAction.class; + + handlerMapping.add(new Handler() + .setController(clazz.newInstance()) + .setMethod(clazz.getMethod("getMemberById",new Class[]{String.class})) + .setUrl("/web/getMemberById.json") + ); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void doService(HttpServletRequest request, HttpServletResponse response){ + doDispatch(request,response); + } + + /** + * 请求的分发工作 + * @param request + * @param response + */ + private void doDispatch(HttpServletRequest request, HttpServletResponse response) { + //1.获取用户请求的url + String uri = request.getRequestURI(); + Handler handler =null; + + ////2、根据uri 去handlerMapping找到对应的hanler + for(Handler h :handlerMapping){ + if(uri.equals(h.getUrl())){ + handler = h; + break; + } + } + //3.将具体的任务分发给Method(通过反射去调用其对应的方法) + Object obj = null; + try { + obj = handler.getMethod().invoke(handler.getController(),request.getParameter("mid")); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + //4、获取到Method执行的结果,通过Response返回出去 + // response.getWriter().write(); + + } + /** + * 具体的hanlder对象 + */ + class Handler{ + //controller对象 + private Object controller; + //controller对象映射的方法 + private String url; + //ulr对应的方法 + private Method method; + + public Object getController() { + return controller; + } + + public Handler setController(Object controller) { + this.controller = controller; + return this; + } + + public String getUrl() { + return url; + } + + public Handler setUrl(String url) { + this.url = url; + return this; + } + + public Method getMethod() { + return method; + } + + public Handler setMethod(Method method) { + this.method = method; + return this; + } + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/AbstractFactory.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/AbstractFactory.java new file mode 100644 index 0000000..86692c7 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/AbstractFactory.java @@ -0,0 +1,30 @@ +package com.funtl.spring.hello.moudule.factory; + +import com.funtl.spring.hello.moudule.simpleFactory.Car; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.factory + * @ClassName: AbstractFactory + * @Author: Administrator + * Date: 2020/1/1 0001 16:35 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 抽象工厂 + */ +public abstract class AbstractFactory { + /** + * 得到奥迪的车 + * @return + */ + public abstract Car getAudiCar(); + /** + * 得到奔驰的车 + * @return + */ + public abstract Car getBenzCar(); + /** + * 得到宝马的车 + * @return + */ + public abstract Car getBmwCar(); +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/AbstractFactoryTest.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/AbstractFactoryTest.java new file mode 100644 index 0000000..1f00cf9 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/AbstractFactoryTest.java @@ -0,0 +1,26 @@ +package com.funtl.spring.hello.moudule.factory; + +import com.funtl.spring.hello.moudule.simpleFactory.Car; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.factory + * @ClassName: AbstractFactoryTest + * @Author: Administrator + * Date: 2020/1/1 0001 16:36 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +public class AbstractFactoryTest { + /** + * 主要创建一个产品族,不同工厂继承父类的抽象工厂创建不同的产品族 + * @param args + */ + public static void main(String[] args) { + //1.先创建具体抽象工厂 + AbstractFactory abstractFactory = new CarFactory(); + //2.根据具体的抽象工厂得到车 + Car audi = abstractFactory.getAudiCar(); + System.out.println(audi.getName()); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/AudiFactory.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/AudiFactory.java new file mode 100644 index 0000000..96c3b8c --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/AudiFactory.java @@ -0,0 +1,20 @@ +package com.funtl.spring.hello.moudule.factory; + +import com.funtl.spring.hello.moudule.simpleFactory.Audi; +import com.funtl.spring.hello.moudule.simpleFactory.Car; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.factory + * @ClassName: AudiFactory + * @Author: Administrator + * Date: 2020/1/1 0001 16:30 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +public class AudiFactory implements Factory { + @Override + public Car getCar() { + return new Audi(); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/BenzFactory.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/BenzFactory.java new file mode 100644 index 0000000..689fa96 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/BenzFactory.java @@ -0,0 +1,20 @@ +package com.funtl.spring.hello.moudule.factory; + +import com.funtl.spring.hello.moudule.simpleFactory.Benz; +import com.funtl.spring.hello.moudule.simpleFactory.Car; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.factory + * @ClassName: BenzFactory + * @Author: Administrator + * Date: 2020/1/1 0001 16:32 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +public class BenzFactory implements Factory { + @Override + public Car getCar() { + return new Benz(); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/BmwFactory.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/BmwFactory.java new file mode 100644 index 0000000..ececfca --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/BmwFactory.java @@ -0,0 +1,20 @@ +package com.funtl.spring.hello.moudule.factory; + +import com.funtl.spring.hello.moudule.simpleFactory.Bmw; +import com.funtl.spring.hello.moudule.simpleFactory.Car; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.factory + * @ClassName: BmwFactory + * @Author: Administrator + * Date: 2020/1/1 0001 16:32 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +public class BmwFactory implements Factory { + @Override + public Car getCar() { + return new Bmw(); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/CarFactory.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/CarFactory.java new file mode 100644 index 0000000..45dde8f --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/CarFactory.java @@ -0,0 +1,30 @@ +package com.funtl.spring.hello.moudule.factory; + +import com.funtl.spring.hello.moudule.simpleFactory.Audi; +import com.funtl.spring.hello.moudule.simpleFactory.Benz; +import com.funtl.spring.hello.moudule.simpleFactory.Bmw; +import com.funtl.spring.hello.moudule.simpleFactory.Car; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.factory + * @ClassName: CarFactory + * @Author: Administrator + * Date: 2020/1/1 0001 16:36 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 抽象工厂的具体实现 + */ +public class CarFactory extends AbstractFactory { + @Override + public Car getAudiCar() { + return new Audi(); + } + @Override + public Car getBenzCar() { + return new Benz(); + } + @Override + public Car getBmwCar() { + return new Bmw(); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/Factory.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/Factory.java new file mode 100644 index 0000000..3527b78 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/Factory.java @@ -0,0 +1,7 @@ +package com.funtl.spring.hello.moudule.factory; + +import com.funtl.spring.hello.moudule.simpleFactory.Car; + +public interface Factory { + Car getCar(); +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/FactoryTest.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/FactoryTest.java new file mode 100644 index 0000000..d625e0f --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/factory/FactoryTest.java @@ -0,0 +1,25 @@ +package com.funtl.spring.hello.moudule.factory; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.factory + * @ClassName: FactoryTest + * @Author: Administrator + * Date: 2020/1/1 0001 16:32 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +public class FactoryTest { + /** + * 通常由应用程序直接使用 new 创建新的对象, 为了将对象的创建和使用相分离, 采用工厂方法模式方法,即应用程序将对象的创建及初始化职责交给工厂对象 + * @param args + */ + public static void main(String[] args) { + //1.首先先创建一个奥迪工厂出来 + Factory factory = new AudiFactory(); + //2.然后根据工厂得到奥迪车,具体的造车工厂交给工厂来完成 + System.out.println(factory.getCar().getName()); + factory = new BmwFactory(); + System.out.println(factory.getCar().getName()); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo1/Message.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo1/Message.java new file mode 100644 index 0000000..8941257 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo1/Message.java @@ -0,0 +1,38 @@ +package com.funtl.spring.hello.moudule.observer.demo1; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.observer + * @ClassName: Message + * @Author: Administrator + * Date: 2020/1/1 0001 10:26 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +public class Message { + private String title; + private String content; + public String getTitle() { + return title; + } + public void setTitle(String title) { + this.title = title; + } + public String getContent() { + return content; + } + public void setContent(String content) { + this.content = content; + } + public Message(String title, String content) { + this.title = title; + this.content = content; + } + @Override + public String toString() { + return "Message{" + + "title='" + title + '\'' + + ", content='" + content + '\'' + + '}'; + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo1/MessageObserver.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo1/MessageObserver.java new file mode 100644 index 0000000..48948d4 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo1/MessageObserver.java @@ -0,0 +1,30 @@ +package com.funtl.spring.hello.moudule.observer.demo1; + +import java.util.Observable; +import java.util.Observer; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.observer + * @ClassName: MessageObserver + * @Author: Administrator + * Date: 2020/1/1 0001 10:25 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +//订阅者 +public class MessageObserver implements Observer { + private String title; + public String getTitle() { + return title; + } + public void setTitle(String title) { + this.title = title; + } + public MessageObserver(String title) { + this.title = title; + } + public void update(Observable o, Object arg) { + System.out.println("observer :" + title + ",receive a message" + arg.toString()); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo1/MessagePublishObservable.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo1/MessagePublishObservable.java new file mode 100644 index 0000000..05dee32 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo1/MessagePublishObservable.java @@ -0,0 +1,51 @@ +package com.funtl.spring.hello.moudule.observer.demo1; + +import java.util.Observable; +import java.util.Observer; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.observer + * @ClassName: MessagePublishObservable + * @Author: Administrator + * Date: 2020/1/1 0001 10:26 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +//发布者 +public class MessagePublishObservable extends Observable { + private Message message; + public MessagePublishObservable(Message message) { + this.message = message; + } + public void pushMessage(){ + setChanged(); + notifyObservers(message); + } + public Message getMessage() { + return message; + } + public void setMessage(Message message) { + this.message = message; + } + @Override + public synchronized void addObserver(Observer o) { + super.addObserver(o); + } + @Override + public synchronized void deleteObserver(Observer o) { + super.deleteObserver(o); + } + @Override + public void notifyObservers() { + super.notifyObservers(); + } + @Override + public void notifyObservers(Object arg) { + super.notifyObservers(arg); + } + @Override + protected synchronized void setChanged() { + super.setChanged(); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo1/Test.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo1/Test.java new file mode 100644 index 0000000..cd84585 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo1/Test.java @@ -0,0 +1,38 @@ +package com.funtl.spring.hello.moudule.observer.demo1; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.observer + * @ClassName: Test + * @Author: Administrator + * Date: 2020/1/1 0001 10:27 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +public class Test { + /** + * 观察者模式 + * 观察者模式(又被称为发布-订阅(Publish/Subscribe)模式,属于行为型模式的一种,它定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个主题对象。这个主题对象在状态变化时,会通知所有的观察者对象,使他们能够自动更新自己。 + * 观察者模式四大角色 + * Subject:抽象主题(抽象被观察者),抽象主题角色把所有观察者对象保存在一个集合里,每个主题都可以有任意数量的观察者,抽象主题提供新增、删除、通知观察者的方法。 + * ConcreteSubject:具体主题(具体被观察者),该角色将有关状态存入具体观察者对象,在具体主题的内部状态发生改变时,给所有注册过的观察者发送通知。 + * Observer:抽象观察者,是观察者者的抽象类,它定义了一个更新接口,使得在得到主题更改通知时更新自己。 + * ConcrereObserver:具体观察者,实现抽象观察者定义的更新接口,以便在得到主题更改通知时更新 + * @param args + */ + public static void main(String[] args) { + MessageObserver messageObserverTopicA = new MessageObserver("A"); + MessageObserver messageObserverTopicB = new MessageObserver("B"); + MessageObserver messageObserverTopicC = new MessageObserver("C"); + MessagePublishObservable messagePublishObservable = new MessagePublishObservable(new Message("关注","欢迎关注享知行")); + //a关注了享知行 + messagePublishObservable.addObserver(messageObserverTopicA); + //b关注了享知行 + messagePublishObservable.addObserver(messageObserverTopicB); + //c关注了享知行 + messagePublishObservable.addObserver(messageObserverTopicC); + messagePublishObservable.pushMessage(); + messagePublishObservable.setMessage(new Message("文章更新","公众号享知行更新啦")); + messagePublishObservable.pushMessage(); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo2/Event.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo2/Event.java new file mode 100644 index 0000000..0905e2c --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo2/Event.java @@ -0,0 +1,87 @@ +package com.funtl.spring.hello.moudule.observer.demo2; + +import java.lang.reflect.Method; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.observer.demo2 + * @ClassName: Event + * @Author: Administrator + * Date: 2020/1/1 0001 19:04 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 事件对象 一个中间对象,保存了事件源,事件的通知对象和方法,以及触发类型,触发时间 + * * 这里面用到链式的写法 + */ +public class Event { + //事件源,谁触发的 + private Object source; + //触发类型的标记 + private String trigger; + //通知的目标对象 + private Object target; + //通知的目标的方法 + private Method callback; + + //触发时间 + private long time; + + public Event(Object target, Method method) { + this.target = target; + this.callback = method; + } + + public Object getSource() { + return source; + } + + public Event setSource(Object source) { + this.source = source; + return this; + } + + public String getTrigger() { + return trigger; + } + + public Event setTrigger(String trigger) { + this.trigger = trigger; + return this; + } + + public Object getTarget() { + return target; + } + + public Event setTarget(Object target) { + this.target = target; + return this; + } + + public Method getCallback() { + return callback; + } + + public void setCallback(Method callback) { + this.callback = callback; + } + + public long getTime() { + return time; + } + + public Event setTime(long time) { + this.time = time; + return this; + } + + @Override + public String toString() { + return "Event{" + + "source=" + source + + ", trigger='" + trigger + '\'' + + ", target=" + target + + ", callback=" + callback + + ", time=" + time + + '}'; + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo2/EventListener.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo2/EventListener.java new file mode 100644 index 0000000..ed71c6c --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo2/EventListener.java @@ -0,0 +1,56 @@ +package com.funtl.spring.hello.moudule.observer.demo2; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.observer.demo2 + * @ClassName: EventListener + * @Author: Administrator + * Date: 2020/1/1 0001 19:05 + * project name: spring-boot-alibaba-samples + * @Version: 抽象的时间源对象,提供公用的事件注册,事件移除,事件触发 + * @Description: 可以认为是一个抽象主题对象, 可以添加和移除观察者,当需要触发的时候,就调用触发方法 + */ +public abstract class EventListener { + //保存事件的容器 + private Map eventMap = new HashMap(); + + //添加监听者对象 + public void addListener(Enum e , Object target , Method method){ + Event event =new Event(target,method); + eventMap.put(e,event); + } + + //移除监听者对象 + public void removeListener(Enum e){ + eventMap.remove(e); + } + /** + * 通过事件来触发 + * @param event + */ + public void trigger(Event event){ + //设置源事件 + event.setSource(this); + event.setTime(System.currentTimeMillis()); + try { + event.getCallback().invoke(event.getTarget(),event); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + } + + //通过触发类型来触发对应的观察者 + public void trigger(Enum e){ + if(!eventMap.keySet().contains(e)){ + return; + } + //先从容器中获取事件,并设置触发类型 + trigger( eventMap.get(e).setTrigger(e.toString())); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo2/Mouse.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo2/Mouse.java new file mode 100644 index 0000000..c014300 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo2/Mouse.java @@ -0,0 +1,33 @@ +package com.funtl.spring.hello.moudule.observer.demo2; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.observer.demo2 + * @ClassName: Mouse + * @Author: Administrator + * Date: 2020/1/1 0001 19:06 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 具体的主题对象,认为是事件对象 鼠标对象,当单击鼠标,就触发单击的时间 + */ +public class Mouse extends EventListener { + public void click(){ + System.out.println("鼠标单击"); + this.trigger(MouseEventType.ON_CLICK); + } + + + public void doubleClick(){ + System.out.println("鼠标双击"); + this.trigger(MouseEventType.ON_DOUBLE_CLICK); + } + + public void up(){ + System.out.println("鼠标弹起"); + this.trigger(MouseEventType.ON_UP); + } + + public void down(){ + System.out.println("鼠标按下"); + this.trigger(MouseEventType.ON_DOWN); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo2/MouseEventCallback.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo2/MouseEventCallback.java new file mode 100644 index 0000000..bf83f5a --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo2/MouseEventCallback.java @@ -0,0 +1,29 @@ +package com.funtl.spring.hello.moudule.observer.demo2; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.observer.demo2 + * @ClassName: MouseEventCallback + * @Author: Administrator + * Date: 2020/1/1 0001 19:07 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 可以认为是观察者,认为是事件监听对象 这里是通过反射调用来通知观察者的 + */ +public class MouseEventCallback { + public void onClick(Event e){ + System.out.println("=======触发鼠标单击事件========\n" + e); + } + public void onDoubleClick(Event e){ + System.out.println("=======触发鼠标双击事件========\n" + e); + } + + public void onUp(Event e){ + System.out.println("=======触发鼠标弹起事件========\n" + e); + } + public void onDown(Event e){ + System.out.println("=======触发鼠标按下事件========\n" + e); + } + public void onMove(Event e){ + System.out.println("=======触发鼠标移动事件========\n" + e); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo2/MouseEventType.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo2/MouseEventType.java new file mode 100644 index 0000000..934fb0a --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo2/MouseEventType.java @@ -0,0 +1,9 @@ +package com.funtl.spring.hello.moudule.observer.demo2; + +//事件的类型 +public enum MouseEventType { + ON_CLICK, + ON_DOUBLE_CLICK, + ON_UP, + ON_DOWN +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo2/MouseTest.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo2/MouseTest.java new file mode 100644 index 0000000..ba301b0 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo2/MouseTest.java @@ -0,0 +1,30 @@ +package com.funtl.spring.hello.moudule.observer.demo2; + +import java.lang.reflect.Method; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.observer.demo2 + * @ClassName: MouseTest + * @Author: Administrator + * Date: 2020/1/1 0001 19:07 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 观察者测试 鼠标对象测试 + * *观察者和被观察者之间没有必然联系 + * *注册的时候,才产生联系 + * *解耦 + */ +public class MouseTest { + public static void main(String[] args) throws NoSuchMethodException { + //事件监听对象 + MouseEventCallback target = new MouseEventCallback(); + //事件监听对象 对应绑定的方法 + Method onClickCallback =target.getClass().getDeclaredMethod("onClick", Event.class); + Mouse mouse = new Mouse(); + //添加观察者对象,这里这是把通知的目标和方法进行封装到一个中间的事件对象身上 + mouse.addListener(MouseEventType.ON_CLICK,target,onClickCallback); + + //通知观察者对象,在这里是触发事件,利用了反射调用来进行通知 + mouse.trigger(MouseEventType.ON_CLICK); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo3/OrderEvent.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo3/OrderEvent.java new file mode 100644 index 0000000..d57f105 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo3/OrderEvent.java @@ -0,0 +1,18 @@ +package com.funtl.spring.hello.moudule.observer.demo3; + +import org.springframework.context.ApplicationEvent; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.observer.demo3 + * @ClassName: OrderEvent + * @Author: Administrator + * Date: 2020/1/1 0001 19:16 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 定义事件 + */ +public class OrderEvent extends ApplicationEvent { + public OrderEvent(Object source) { + super(source); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo3/OrderPublish.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo3/OrderPublish.java new file mode 100644 index 0000000..25aed61 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo3/OrderPublish.java @@ -0,0 +1,33 @@ +package com.funtl.spring.hello.moudule.observer.demo3; + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.ApplicationEvent; +import org.springframework.stereotype.Service; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.observer.demo3 + * @ClassName: OrderPublish + * @Author: Administrator + * Date: 2020/1/1 0001 19:17 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 事件发布器。把事件发布到 spring容器中。 + */ +@Service +public class OrderPublish implements ApplicationContextAware { + + private ApplicationContext applicationContext; + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + // 获取spring容器,设置到私有属性。 + this.applicationContext = applicationContext; + } + + // 调用spring容器 发布事件 + public void publishEvent(ApplicationEvent event){ + applicationContext.publishEvent(event); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo3/OrderService.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo3/OrderService.java new file mode 100644 index 0000000..f4fe47f --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo3/OrderService.java @@ -0,0 +1,35 @@ +package com.funtl.spring.hello.moudule.observer.demo3; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.observer.demo3 + * @ClassName: OrderService + * @Author: Administrator + * Date: 2020/1/1 0001 19:17 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 订单操作,业务伪代码 + */ +@Service +public class OrderService { + // 注入事件发布器 + @Autowired + private OrderPublish orderPublish; + + /** + * 电商 - 新订单订单 + */ + public void saveOrder() { + + System.out.println("1、 订单创建成功"); + + // 创建事件 ,可以设置参数 + OrderEvent orderEvent = new OrderEvent(123456); + + // 发布事件 + orderPublish.publishEvent(orderEvent); + + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo3/SmsListener.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo3/SmsListener.java new file mode 100644 index 0000000..3a96d53 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/observer/demo3/SmsListener.java @@ -0,0 +1,26 @@ +package com.funtl.spring.hello.moudule.observer.demo3; + +import org.springframework.context.ApplicationListener; +import org.springframework.stereotype.Component; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.observer.demo3 + * @ClassName: SmsListener + * @Author: Administrator + * Date: 2020/1/1 0001 19:18 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 监听器 ,有事件发布后,才会执行 + */ +@Component +public class SmsListener implements ApplicationListener { + @Override + public void onApplicationEvent(OrderEvent event) { + + // 获取事件中的参数。 + System.out.println("event.getSource的值是:"+event.getSource()); + + // 2---短信通知 + System.out.println("2、 调用短信发送的接口 -> 恭喜喜提羽绒被子"); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/Man.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/Man.java new file mode 100644 index 0000000..2e1efeb --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/Man.java @@ -0,0 +1,18 @@ +package com.funtl.spring.hello.moudule.proxy; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.proxy + * @ClassName: Man + * @Author: Administrator + * Date: 2020/1/1 0001 17:35 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 目标对象 + */ +public class Man implements Person { + //找对象 + @Override + public void findLove() { + System.out.println("我是一个男人,想找一位女朋友"); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/Person.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/Person.java new file mode 100644 index 0000000..fa712ea --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/Person.java @@ -0,0 +1,6 @@ +package com.funtl.spring.hello.moudule.proxy; + +public interface Person { + //找对象 + void findLove(); +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/Test.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/Test.java new file mode 100644 index 0000000..661440b --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/Test.java @@ -0,0 +1,44 @@ +package com.funtl.spring.hello.moudule.proxy; + +import com.funtl.spring.hello.moudule.proxy.jdkProxy.MeiPo; +import sun.misc.ProxyGenerator; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.proxy + * @ClassName: Test + * @Author: Administrator + * Date: 2020/1/1 0001 17:38 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: jdk动态方法测试 + */ +public class Test { + public static void main(String[] args) { + + Person xiaoming = new Man(); + + Person meipo = new MeiPo().getInstance(xiaoming); + + meipo.findLove(); + + //原理: + //1、拿到被代理对象的引用,并且获取到它的所有的接口,反射获取 (获取接口) + //2、JDK Proxy类重新生成一个新的类、同时新的类要实现被代理类所有实现的所有的接口 (实现接口) + //3、动态生成Java代码,把新加的业务逻辑方法由一定的逻辑代码去调用(在代码中体现)(生成java代码) + //4、编译新生成的Java代码.class (编译) + //5、再重新加载到JVM中运行 (加载) + + //这里是接口的代码生成器 + byte[] data = ProxyGenerator.generateProxyClass("$Proxy0",new Class[]{Person.class}); + try { + //此为jdk 1.7发行的nio的类 作用是把 data 数据写到 文件 $Proxy0.class中 + Files.newOutputStream(Paths.get("$Proxy0.class")).write(data); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/cglibproxy/CgMan.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/cglibproxy/CgMan.java new file mode 100644 index 0000000..a710fe0 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/cglibproxy/CgMan.java @@ -0,0 +1,16 @@ +package com.funtl.spring.hello.moudule.proxy.cglibproxy; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.proxy + * @ClassName: CgMan + * @Author: Administrator + * Date: 2020/1/1 0001 17:43 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: cglib 目标对象 + */ +public class CgMan { + public void findLove() { + System.out.println("我是一个男人,想找一位女朋友"); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/cglibproxy/CgMeiPo.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/cglibproxy/CgMeiPo.java new file mode 100644 index 0000000..5949890 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/cglibproxy/CgMeiPo.java @@ -0,0 +1,46 @@ +package com.funtl.spring.hello.moudule.proxy.cglibproxy; + +import org.springframework.cglib.proxy.Enhancer; +import org.springframework.cglib.proxy.MethodInterceptor; +import org.springframework.cglib.proxy.MethodProxy; + +import java.lang.reflect.Method; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.proxy + * @ClassName: CgMeiPo + * @Author: Administrator + * Date: 2020/1/1 0001 17:44 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: cglib动态代理 媒婆 + * * 需要实现 MethodInterceptor接口 + */ +public class CgMeiPo implements MethodInterceptor { + + public Object getInstance(Class clazz){ + Enhancer enhancer = new Enhancer(); + //cglib 主要根据继承来生成代码的关系 + //设置父类 + enhancer.setSuperclass(clazz); + //设置回调 就是代理类通过 MethodInterceptor 找到 intercept方法进行回调 + enhancer.setCallback(this); + //crate 方法 + //第一步、生成源代码 + //第二步、编译成class文件 + //第三步、加载到JVM中,并返回被代理对象 + return enhancer.create(); + } + + @Override + public Object intercept(Object obj, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { + System.out.println("我是媒婆,通过cglib 来实现的"); + //这样就会循环触发调用 + //cglib的代理实际上原有的对象的子类,通过继承来实现,这里默认调用父类的方法,obj 为cglib代理的子类 + //切记不要写成 methodProxy.invoke(obj,args); 这里面就会存在循环调用的问题,这里会调用cglib代理类,然后循环调用 + //调用父类 + methodProxy.invokeSuper(obj,args); + System.out.println("正在帮你找"); + return null; + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/cglibproxy/CgTest.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/cglibproxy/CgTest.java new file mode 100644 index 0000000..9926bef --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/cglibproxy/CgTest.java @@ -0,0 +1,18 @@ +package com.funtl.spring.hello.moudule.proxy.cglibproxy; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.proxy + * @ClassName: CgTest + * @Author: Administrator + * Date: 2020/1/1 0001 17:44 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +public class CgTest { + public static void main(String[] args) { + CgMan xiaoming = new CgMan(); + CgMan cgmeipo = (CgMan) new CgMeiPo().getInstance(xiaoming.getClass()); + cgmeipo.findLove(); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/jdkProxy/MeiPo.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/jdkProxy/MeiPo.java new file mode 100644 index 0000000..fb73847 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/jdkProxy/MeiPo.java @@ -0,0 +1,40 @@ +package com.funtl.spring.hello.moudule.proxy.jdkProxy; + + +import com.funtl.spring.hello.moudule.proxy.Person; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.proxy + * @ClassName: MeiPo + * @Author: Administrator + * Date: 2020/1/1 0001 17:36 + * project name: spring-boot-alibaba-samples + * @Version: jdk动态代理对象 媒婆 + * @Description: 代理对象 媒婆 + */ +public class MeiPo implements InvocationHandler { + + private Person person; + + public Person getInstance(Person person){ + this.person = person; + Class clazz = person.getClass(); + System.out.println("原有的person的类为:"+clazz.getName()); + //基于jdk 中Proxy类用来生成一个新的对象(字节码重组来实现) + return (Person) Proxy.newProxyInstance(clazz.getClassLoader(),clazz.getInterfaces(),this); + } + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + System.out.println("代理类为:"+proxy.getClass()); + System.out.println("我是媒婆"); + //这样就会循环触发调用 + //method.invoke(proxy,args); + method.invoke(person,args); + System.out.println("正在帮你找"); + return null; + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/proxyDefine/CuClassLoader.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/proxyDefine/CuClassLoader.java new file mode 100644 index 0000000..df73f31 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/proxyDefine/CuClassLoader.java @@ -0,0 +1,29 @@ +package com.funtl.spring.hello.moudule.proxy.proxyDefine; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.proxy + * @ClassName: CuClassLoader + * @Author: Administrator + * Date: 2020/1/1 0001 17:50 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 自定义的类加载器 + * * 要实现 findClass对象 实现自定义类的加载 + * * 最后通过findclass 的native方法加载返回类 + */ +public class CuClassLoader extends ClassLoader { + + private byte[] bytes ; + + public CuClassLoader(byte[] bytes) { + this.bytes = bytes; + } + + @Override + protected Class findClass(String name) throws ClassNotFoundException { + + String className = CuClassLoader.class.getPackage().getName() + "." + name; + + return defineClass(name,bytes,0,bytes.length); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/proxyDefine/CuMan.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/proxyDefine/CuMan.java new file mode 100644 index 0000000..993f9ec --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/proxyDefine/CuMan.java @@ -0,0 +1,17 @@ +package com.funtl.spring.hello.moudule.proxy.proxyDefine; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.proxy + * @ClassName: CuMan + * @Author: Administrator + * Date: 2020/1/1 0001 17:49 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 自定义的目标对象 + */ +public class CuMan implements CuPerson { + @Override + public void findLove() { + System.out.println("我是一个男人,想找一位女朋友"); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/proxyDefine/CuMeipo.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/proxyDefine/CuMeipo.java new file mode 100644 index 0000000..484e34c --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/proxyDefine/CuMeipo.java @@ -0,0 +1,38 @@ +package com.funtl.spring.hello.moudule.proxy.proxyDefine; + + + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.proxy + * @ClassName: CuMeipo + * @Author: Administrator + * Date: 2020/1/1 0001 17:49 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +public class CuMeipo implements InvocationHandler { + + private CuPerson person; + + public CuPerson getInstance(CuPerson person){ + this.person = person; + Class clazz = person.getClass(); + System.out.println("原有的person的类为:"+clazz.getName()); + return (CuPerson) CuProxy.newProxyInstance(clazz.getInterfaces(),this); + } + + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + System.out.println("代理类为:"+proxy.getClass()); + System.out.println("我是媒婆"); + //这样就会循环触发调用 + //method.invoke(proxy,args); + method.invoke(person,args); + System.out.println("正在帮你找"); + return null; + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/proxyDefine/CuPerson.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/proxyDefine/CuPerson.java new file mode 100644 index 0000000..4da3bdf --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/proxyDefine/CuPerson.java @@ -0,0 +1,6 @@ +package com.funtl.spring.hello.moudule.proxy.proxyDefine; + +//自定义的Person接口 +public interface CuPerson { + void findLove(); +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/proxyDefine/CuProxy.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/proxyDefine/CuProxy.java new file mode 100644 index 0000000..8372159 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/proxyDefine/CuProxy.java @@ -0,0 +1,44 @@ +package com.funtl.spring.hello.moudule.proxy.proxyDefine; + + + +import com.funtl.spring.hello.moudule.proxy.proxyDefine.CuClassLoader; +import sun.misc.ProxyGenerator; + +import java.io.OutputStream; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationHandler; +import java.nio.file.Files; +import java.nio.file.Paths; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.proxy + * @ClassName: CuProxy + * @Author: Administrator + * Date: 2020/1/1 0001 17:49 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 自定义的生成代理类的实现 + */ +public class CuProxy { + public static Object newProxyInstance(Class[] interfaces,InvocationHandler h) { + //1.根据接口生成class文件 + byte[] bytes = ProxyGenerator.generateProxyClass("$Proxy0", interfaces); + try { + //写入一个文件可以查看生成的源代码 + OutputStream os = Files.newOutputStream(Paths.get("$Proxy0.class")); + os.write(bytes); + //2.通过自定义类加载器动态加载代理类 + CuClassLoader loader = new CuClassLoader(bytes); + Class proxyClazz = loader.loadClass("$Proxy0"); + //3.得到代理类的构造方法 + System.out.println(proxyClazz.getName()); + Constructor construct = proxyClazz.getConstructor(InvocationHandler.class); + //4.返回代理对象 + return construct.newInstance(h); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/proxyDefine/CuTest.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/proxyDefine/CuTest.java new file mode 100644 index 0000000..ccb1c7d --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/proxyDefine/CuTest.java @@ -0,0 +1,22 @@ +package com.funtl.spring.hello.moudule.proxy.proxyDefine; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.proxy + * @ClassName: CuTest + * @Author: Administrator + * Date: 2020/1/1 0001 17:50 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 自定义的测试方法 + */ +public class CuTest { + /** + * 主要根据ProxyGenerator类生成传入的接口的字节码,然后根据自定义的类加载器加载字节码得到具体的代理类,通过反射得到代理类的构造方法,最后通过反射构造新对象返回对象 + * @param args + */ + public static void main(String[] args) { + CuPerson xiaoming = new CuMan(); + CuPerson meipo = new CuMeipo().getInstance(xiaoming); + meipo.findLove(); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/staticProxy/StaticProxy.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/staticProxy/StaticProxy.java new file mode 100644 index 0000000..2ed3b86 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/proxy/staticProxy/StaticProxy.java @@ -0,0 +1,32 @@ +package com.funtl.spring.hello.moudule.proxy.staticProxy; + +import com.funtl.spring.hello.moudule.proxy.Man; +import com.funtl.spring.hello.moudule.proxy.Person; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.proxy + * @ClassName: StaticProxy + * @Author: Administrator + * Date: 2020/1/1 0001 17:35 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 静态代理 实现目标对象的代理 + */ +public class StaticProxy implements Person { + + private Person person; + + public StaticProxy(Person person) { + this.person = person; + } + public void findLove(){ + System.out.println("根据你的要求物色"); + this.person.findLove(); + System.out.println("双方父母是不是同意"); + } + //静态代理测试 + public static void main(String[] args) { + StaticProxy staticProxy = new StaticProxy(new Man()); + staticProxy.findLove(); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/simpleFactory/Audi.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/simpleFactory/Audi.java new file mode 100644 index 0000000..9d140e8 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/simpleFactory/Audi.java @@ -0,0 +1,17 @@ +package com.funtl.spring.hello.moudule.simpleFactory; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.Factory + * @ClassName: Audi + * @Author: Administrator + * Date: 2020/1/1 0001 16:24 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +public class Audi implements Car { + @Override + public String getName() { + return "audi"; + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/simpleFactory/Benz.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/simpleFactory/Benz.java new file mode 100644 index 0000000..6163d32 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/simpleFactory/Benz.java @@ -0,0 +1,17 @@ +package com.funtl.spring.hello.moudule.simpleFactory; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.Factory + * @ClassName: Benz + * @Author: Administrator + * Date: 2020/1/1 0001 16:24 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +public class Benz implements Car { + @Override + public String getName() { + return "benz"; + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/simpleFactory/Bmw.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/simpleFactory/Bmw.java new file mode 100644 index 0000000..18d6e06 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/simpleFactory/Bmw.java @@ -0,0 +1,17 @@ +package com.funtl.spring.hello.moudule.simpleFactory; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.Factory + * @ClassName: Bmw + * @Author: Administrator + * Date: 2020/1/1 0001 16:24 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +public class Bmw implements Car { + @Override + public String getName() { + return "bmw"; + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/simpleFactory/Car.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/simpleFactory/Car.java new file mode 100644 index 0000000..33070a3 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/simpleFactory/Car.java @@ -0,0 +1,5 @@ +package com.funtl.spring.hello.moudule.simpleFactory; + +public interface Car { + String getName(); +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/simpleFactory/SimpleFactory.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/simpleFactory/SimpleFactory.java new file mode 100644 index 0000000..1535904 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/simpleFactory/SimpleFactory.java @@ -0,0 +1,25 @@ +package com.funtl.spring.hello.moudule.simpleFactory; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.Factory + * @ClassName: SimpleFactory + * @Author: Administrator + * Date: 2020/1/1 0001 16:25 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 简单工厂 根据传入不同的参数得到不同对象 + */ +public class SimpleFactory { + public Car getCar(String name){ + if("BMW".equalsIgnoreCase(name)){ + return new Bmw(); + }else if("Benz".equalsIgnoreCase(name)){ + return new Benz(); + }else if("Audi".equalsIgnoreCase(name)){ + return new Audi(); + }else{ + System.out.println("这个产品产不出来"); + return null; + } + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/singleton/BeanFactory.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/singleton/BeanFactory.java new file mode 100644 index 0000000..9689cba --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/singleton/BeanFactory.java @@ -0,0 +1,34 @@ +package com.funtl.spring.hello.moudule.singleton; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.singleton + * @ClassName: BeanFactory + * @Author: Administrator + * Date: 2020/1/1 0001 16:58 + * project name: spring-boot-alibaba-samples + * @Version: 登记式 + * @Description: 用一个map容器来实现登记式单例 + */ +public class BeanFactory { + private BeanFactory(){ } + //用ConcurrentHashMap保存bean,保证了线程的安全性 + private static Map ioc = new ConcurrentHashMap(); + + public synchronized static Object getBean(String className){ + if( !ioc.containsKey(className)){ + Object obj = null; + try { + obj = Class.forName(className).newInstance(); + ioc.put(className,obj); + } catch (Exception e) { + e.printStackTrace(); + } + return obj; + }else { + return ioc.get(className); + } + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/singleton/Hungry.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/singleton/Hungry.java new file mode 100644 index 0000000..d739120 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/singleton/Hungry.java @@ -0,0 +1,28 @@ +package com.funtl.spring.hello.moudule.singleton; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.singleton + * @ClassName: Hungry + * @Author: Administrator + * Date: 2020/1/1 0001 16:52 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + * 它是在类加载的时候就立即初始化,并且创建单例对象 + * 优点:没有加任何的锁、执行效率比较高 + * 在用户体验上来说,比懒汉式更好 + * 缺点:类加载的时候就初始化,不管你用还是不用,我都占着空间 + * 浪费了内存,有可能这个类不使用,但是在类加载的时候就初始化了 + * + * 绝对线程安全,在线程还没出现以前就是实例化了,不可能存在访问安全问题 + * + */ +public class Hungry { + private Hungry(){} + + private static final Hungry hungry = new Hungry(); + + public static Hungry getInstance(){ + return hungry; + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/singleton/LazyFour.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/singleton/LazyFour.java new file mode 100644 index 0000000..532b9f3 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/singleton/LazyFour.java @@ -0,0 +1,30 @@ +package com.funtl.spring.hello.moudule.singleton; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.singleton + * @ClassName: LazyFour + * @Author: Administrator + * Date: 2020/1/1 0001 16:57 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 基于双重检查锁的机制实现的单例模式 + */ +public class LazyFour { + //静态块,公共内存区域 + private static LazyFour lazy = null; + + private LazyFour(){} + + public static LazyFour getInstance(){ + if(lazy == null){ + //存在多个线程,跑进来在这里 + synchronized (LazyFour.class){ + //后面进来的线程需要判断lazy是否已经初始化了,不然的话,会重新创建新的对象 + if(lazy == null){ + lazy = new LazyFour(); + } + } + } + return lazy; + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/singleton/LazyOne.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/singleton/LazyOne.java new file mode 100644 index 0000000..ea2a885 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/singleton/LazyOne.java @@ -0,0 +1,28 @@ +package com.funtl.spring.hello.moudule.singleton; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.singleton + * @ClassName: LazyOne + * @Author: Administrator + * Date: 2020/1/1 0001 16:53 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 懒汉式单例,但是多线程的情况下不安全 + */ +public class LazyOne { + private LazyOne(){} + //静态块,公共内存区域 + private static LazyOne lazy = null; + + public static LazyOne getInstance(){ + //调用方法之前,先判断 + //如果没有初始化,将其进行初始化,并且赋值 + //将该实例缓存好 + if(lazy == null){ + //两个线程都会进入这个if里面 + lazy = new LazyOne(); + } + //如果已经初始化,直接返回之前已经保存好的结果 + return lazy; + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/singleton/LazyThree.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/singleton/LazyThree.java new file mode 100644 index 0000000..7e095f1 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/singleton/LazyThree.java @@ -0,0 +1,43 @@ +package com.funtl.spring.hello.moudule.singleton; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.singleton + * @ClassName: LazyThree + * @Author: Administrator + * Date: 2020/1/1 0001 16:54 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + * 基于内部类方式实现的单例模式 + * 特点:在外部类被调用的时候内部类才会被加载 + * 内部类一定是要在方法调用之前初始化 + * 巧妙地避免了线程安全问题 + * 这种形式兼顾饿汉式的内存浪费,也兼顾synchronized性能问题 + * 完美地屏蔽了这两个缺点 + * 史上最牛的单例模式的实现方式 + */ +public class LazyThree { + private boolean initailzed = false; + //1.构造方法私有 + private LazyThree(){ + //可以优化点 就是反射进行反射得到单例对象,第一次得到设置标记,后面得到则报错 + synchronized (LazyThree.class){ + if(!initailzed){ + initailzed = !initailzed; + }else { + throw new RuntimeException("单例已被侵犯"); + } + } + } + //2.构造内部类持有单例对象 + //内部类默认是不加载的,只有访问到内部类的属性或者方法的时候才加载内部类 + private static final class LazyHolder{ + private static final LazyThree lazy = new LazyThree(); + } + //3.公共的全局的方法的访问点 + //static 是为了使单例的空间共享 + //final 保证这个方法不会被重写,重载 + public LazyThree getInstance(){ + return LazyHolder.lazy; + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/singleton/LazyTwo.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/singleton/LazyTwo.java new file mode 100644 index 0000000..e3eb39a --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/singleton/LazyTwo.java @@ -0,0 +1,23 @@ +package com.funtl.spring.hello.moudule.singleton; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.singleton + * @ClassName: LazyTwo + * @Author: Administrator + * Date: 2020/1/1 0001 16:54 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 基于加锁的线程安全的懒汉式单例 + */ +public class LazyTwo { + private LazyTwo(){} + + private static LazyTwo lazy = null; + //加锁 来保证多线程的情况下也是一个单例 + public static synchronized LazyTwo getInstance(){ + if(lazy == null){ + lazy = new LazyTwo(); + } + return lazy; + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/singleton/enumSingleton.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/singleton/enumSingleton.java new file mode 100644 index 0000000..84cf018 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/singleton/enumSingleton.java @@ -0,0 +1,24 @@ +package com.funtl.spring.hello.moudule.singleton; +/** + * @PackgeName: com.funtl.spring.hello.moudule.singleton + * @ClassName: BeanFactory + * @Author: Administrator + * Date: 2020/1/1 0001 16:58 + * project name: spring-boot-alibaba-samples + * @Version: 枚举式 + * @Description: 基于枚举实现的单例 + * 特定: + * 自由序列化。 + * 保证只有一个实例。 + * 线程安全 + */ +public enum enumSingleton { + INSTANCE; + public void otherMethods(){ + System.out.println("Something"); + } + public static void main(String[] args) { + //进行单例的调用 + enumSingleton.INSTANCE.otherMethods(); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/AliPay.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/AliPay.java new file mode 100644 index 0000000..b510e99 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/AliPay.java @@ -0,0 +1,19 @@ +package com.funtl.spring.hello.moudule.strategy.demo1; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.strategy + * @ClassName: AliPay + * @Author: Administrator + * Date: 2020/1/1 0001 18:09 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +public class AliPay implements Payment{ + @Override + public PayState pay(String uid, double amount) { + System.out.println("欢迎来到支付宝支付"); + System.out.println("开始查询余额,开始扣款"); + return new PayState(200,"支付成功",uid,amount); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/Order.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/Order.java new file mode 100644 index 0000000..649a659 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/Order.java @@ -0,0 +1,26 @@ +package com.funtl.spring.hello.moudule.strategy.demo1; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.strategy + * @ClassName: Order + * @Author: Administrator + * Date: 2020/1/1 0001 18:10 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 模拟一个订单类 + */ +public class Order { + private String uid; + private String oid; + private double amount; + + public Order(String uid, String oid, double amount) { + this.uid = uid; + this.oid = oid; + this.amount = amount; + } + //为订单支付 + public PayState pay(PayType payType){ + return payType.get().pay(uid,amount); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/PayState.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/PayState.java new file mode 100644 index 0000000..b825d61 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/PayState.java @@ -0,0 +1,38 @@ +package com.funtl.spring.hello.moudule.strategy.demo1; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.strategy + * @ClassName: PayState + * @Author: Administrator + * Date: 2020/1/1 0001 18:08 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 支付后的状态 + */ +public class PayState { + //支付后的状态码 + private int code; + //支付后的消息提示 + private String msg; + //代表谁支付的 + private String uid ; + //支付的数据大小 + private Object data; + + public PayState(int code, String msg, String uid, Object data) { + this.code = code; + this.msg = msg; + this.uid = uid; + this.data = data; + } + + @Override + public String toString() { + return "payState{" + + "code=" + code + + ", msg='" + msg + '\'' + + ", uid='" + uid + '\'' + + ", data=" + data + + '}'; + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/PayType.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/PayType.java new file mode 100644 index 0000000..9751805 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/PayType.java @@ -0,0 +1,17 @@ +package com.funtl.spring.hello.moudule.strategy.demo1; +//支付方式的一个context +public enum PayType { + ALI_PAY(new AliPay()), + WECHAT_PAY(new AliPay()), + UNION_PAY(new AliPay()); + + private Payment payment ; + + PayType(Payment payment) { + this.payment = payment; + } + + public Payment get(){ + return this.payment; + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/Payment.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/Payment.java new file mode 100644 index 0000000..cccf81b --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/Payment.java @@ -0,0 +1,11 @@ +package com.funtl.spring.hello.moudule.strategy.demo1; +//支付方式的接口 +public interface Payment { + /** + * + * @param uid 表示人的uid + * @param amount 表示支付的金额 + * @return + */ + PayState pay(String uid, double amount); +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/StrategyTest.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/StrategyTest.java new file mode 100644 index 0000000..98ba57f --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/StrategyTest.java @@ -0,0 +1,20 @@ +package com.funtl.spring.hello.moudule.strategy.demo1; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.strategy + * @ClassName: StrategyTest + * @Author: Administrator + * Date: 2020/1/1 0001 18:11 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 策略模式测试 + */ +public class StrategyTest { + public static void main(String[] args) { + Order order = new Order("1","order101",43.23); + + //比如选择阿里支付 + PayState payState = order.pay(PayType.ALI_PAY); + System.out.println(payState); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/UnionPay.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/UnionPay.java new file mode 100644 index 0000000..761f14d --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/UnionPay.java @@ -0,0 +1,19 @@ +package com.funtl.spring.hello.moudule.strategy.demo1; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.strategy + * @ClassName: UnionPay + * @Author: Administrator + * Date: 2020/1/1 0001 18:09 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +public class UnionPay implements Payment { + @Override + public PayState pay(String uid, double amount) { + System.out.println("欢迎来到银联闪付"); + System.out.println("开始查询余额,开始扣款"); + return new PayState(200,"支付成功",uid,amount); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/WechatPay.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/WechatPay.java new file mode 100644 index 0000000..8ca17c7 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo1/WechatPay.java @@ -0,0 +1,19 @@ +package com.funtl.spring.hello.moudule.strategy.demo1; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.strategy + * @ClassName: WechatPay + * @Author: Administrator + * Date: 2020/1/1 0001 18:09 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +public class WechatPay implements Payment { + @Override + public PayState pay(String uid, double amount) { + System.out.println("欢迎来到微信支付"); + System.out.println("开始查询余额,开始扣款"); + return new PayState(200,"支付成功",uid,amount); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo2/Calculator.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo2/Calculator.java new file mode 100644 index 0000000..3330db8 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo2/Calculator.java @@ -0,0 +1,8 @@ +package com.funtl.spring.hello.moudule.strategy.demo2; + +/** + * 抽象策略角色 + */ +public interface Calculator { + public double calculate(double num1,double num2); +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo2/Context.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo2/Context.java new file mode 100644 index 0000000..97b68e3 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo2/Context.java @@ -0,0 +1,28 @@ +package com.funtl.spring.hello.moudule.strategy.demo2; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.strategy + * @ClassName: Context + * @Author: Administrator + * Date: 2020/1/1 0001 15:25 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +//定义计算 + //环境角色 +public class Context { + private Calculator calculator; + public Context(Calculator calculator) { + this.calculator = calculator; + } + public double executeStrategy(int num1, int num2){ + return calculator.calculate(num1, num2); + } + public Calculator getCalculator() { + return calculator; + } + public void setCalculator(Calculator calculator) { + this.calculator = calculator; + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo2/OptionAdd.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo2/OptionAdd.java new file mode 100644 index 0000000..a1f2731 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo2/OptionAdd.java @@ -0,0 +1,19 @@ +package com.funtl.spring.hello.moudule.strategy.demo2; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.strategy + * @ClassName: OptionAdd + * @Author: Administrator + * Date: 2020/1/1 0001 15:23 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +//加法实现 + //具体策略角色 +public class OptionAdd implements Calculator { + @Override + public double calculate(double num1, double num2) { + return num1 + num2; + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo2/OptionDivide.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo2/OptionDivide.java new file mode 100644 index 0000000..90f330e --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo2/OptionDivide.java @@ -0,0 +1,17 @@ +package com.funtl.spring.hello.moudule.strategy.demo2; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.strategy + * @ClassName: OptionDivide + * @Author: Administrator + * Date: 2020/1/1 0001 15:24 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +//除法实现 +public class OptionDivide implements Calculator{ + public double calculate(double num1, double num2) { + return num1 / num2; + } +} \ No newline at end of file diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo2/OptionMultiply.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo2/OptionMultiply.java new file mode 100644 index 0000000..c7e6283 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo2/OptionMultiply.java @@ -0,0 +1,18 @@ +package com.funtl.spring.hello.moudule.strategy.demo2; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.strategy + * @ClassName: OptionMultiply + * @Author: Administrator + * Date: 2020/1/1 0001 15:24 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +//乘法实现 +public class OptionMultiply implements Calculator { + @Override + public double calculate(double num1, double num2) { + return num1 * num2; + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo2/OptionSubstract.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo2/OptionSubstract.java new file mode 100644 index 0000000..f36a843 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo2/OptionSubstract.java @@ -0,0 +1,18 @@ +package com.funtl.spring.hello.moudule.strategy.demo2; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.strategy + * @ClassName: OptionSubstract + * @Author: Administrator + * Date: 2020/1/1 0001 15:24 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +//减法实现 +public class OptionSubstract implements Calculator { + @Override + public double calculate(double num1, double num2) { + return num1 - num2; + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo2/Test.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo2/Test.java new file mode 100644 index 0000000..3ad9382 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/strategy/demo2/Test.java @@ -0,0 +1,33 @@ +package com.funtl.spring.hello.moudule.strategy.demo2; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.strategy + * @ClassName: Test + * @Author: Administrator + * Date: 2020/1/1 0001 15:25 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +public class Test { + /** + * 抽象策略角色(Strategy):这是一个抽象类或者接口,将算法的行为进行封装,所有的策略类都要实现该接口 + * 具体策略角色(ConcreteStrategy):封装了具体的算法和行为 + * 环境角色(Context):持有一个抽象策略的引用,并提供统一调用的入口 + * @param args + */ + public static void main(String[] args) { + Context context = new Context(new OptionAdd()); + double result = context.executeStrategy(1,3); + System.out.println("add:" + result); + context.setCalculator(new OptionSubstract()); + result = context.executeStrategy(1,3); + System.out.println("substract:" + result); + context.setCalculator(new OptionMultiply()); + result = context.executeStrategy(1,3); + System.out.println("multiply:" + result); + context.setCalculator(new OptionDivide()); + result = context.executeStrategy(1,3); + System.out.println("divide:" + result); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/template/JdbcTemplate.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/template/JdbcTemplate.java new file mode 100644 index 0000000..b6fd3e5 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/template/JdbcTemplate.java @@ -0,0 +1,133 @@ +package com.funtl.spring.hello.moudule.template; + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.template + * @ClassName: JdbcTemplate + * @Author: Administrator + * Date: 2020/1/1 0001 18:23 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: jdbc 的模板类 + */ +public class JdbcTemplate { + /** + * 模拟试下了一个jdbcTemplate模板类, + * 比如从数据源中获取一个链接, + * 然后创建语句集, + * 执行语句集获取结果集, + * 解析结果集, + * 最后结果集、语句集、连接的关闭都是固定的流程, + * 而一个对象的如何映射成一个对象是需要具体的实现, + * 这个由具体调用类实现对象的映射, + * 这个步骤是可以重新定义的 + */ + private DataSource dataSource ; + + public JdbcTemplate(DataSource dataSource) { + this.dataSource = dataSource; + } + /** + * 得到连接 + * @return + * @throws SQLException + */ + private Connection getConnection() throws SQLException { + return this.dataSource.getConnection(); + } + + /** + * 获得标准的语句集 + * @param sql + * @param connection + * @return + * @throws SQLException + */ + private PreparedStatement getPreparedStatement(String sql,Connection connection) throws SQLException { + return connection.prepareStatement(sql); + } + + /** + * 得到结果集 + * @param preparedStatement + * @param values + * @return + * @throws SQLException + */ + private ResultSet getResultSet(PreparedStatement preparedStatement,Object[] values) throws SQLException { + int i=0; + for (Object value: values){ + preparedStatement.setObject(i++,value); + } + return preparedStatement.getResultSet(); + } + /** + * 解析结果集 + * @param resultSet + * @param rowMapper + * @return + * @throws Exception + */ + private List parsedResultSet(ResultSet resultSet,RowMapper rowMapper) throws Exception { + int rownumber = 1; + List list = new ArrayList(); + while (resultSet.next()){ + list.add (rowMapper.mapRow(resultSet,rownumber++)); + } + return list; + } + /** + * 关闭结果集 + * @param rs + * @throws SQLException + */ + private void closeResultSet(ResultSet rs) throws SQLException { + rs.close(); + } + /** + * 关闭语句集 + * @param statement + * @throws SQLException + */ + private void closePreparedStatement(PreparedStatement statement ) throws SQLException { + statement.close(); + } + /** + * 关闭连接 + * @param connection + * @throws SQLException + */ + private void closeConnect(Connection connection ) throws SQLException { + //通常把它放到连接池回收 + connection.close(); + } + public List executeQuery(String sql , RowMapper mapper , Object[] values){ + try { + //1.获得连接 + Connection connection = this.getConnection(); + //2.获取语句集 + PreparedStatement pstm = this.getPreparedStatement(sql,connection); + //3.执行语句集,获得结果集 + ResultSet rs= this.getResultSet(pstm,values); + //4.解析结果集 + List list = this.parsedResultSet(rs,mapper); + //5.关闭结果集 + this.closeResultSet(rs); + //6.关闭语句集 + this.closePreparedStatement(pstm); + //7.关闭连接 + this.closeConnect(connection); + return list; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/template/Merber.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/template/Merber.java new file mode 100644 index 0000000..1c82b74 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/template/Merber.java @@ -0,0 +1,59 @@ +package com.funtl.spring.hello.moudule.template; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.template + * @ClassName: Merber + * @Author: Administrator + * Date: 2020/1/1 0001 18:24 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: Merber bean对象 + */ +public class Merber { + private String userName; + private String password; + private String nickName; + + private int age; + private String addr; + + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getNickName() { + return nickName; + } + + public void setNickName(String nickName) { + this.nickName = nickName; + } + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public String getAddr() { + return addr; + } + + public void setAddr(String addr) { + this.addr = addr; + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/template/MerberDao.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/template/MerberDao.java new file mode 100644 index 0000000..397368f --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/template/MerberDao.java @@ -0,0 +1,35 @@ +package com.funtl.spring.hello.moudule.template; + +import java.sql.ResultSet; +import java.util.List; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.template + * @ClassName: MerberDao + * @Author: Administrator + * Date: 2020/1/1 0001 18:24 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +public class MerberDao { + //为什么不继承,主要是为了解耦 + //这里没有传直接的数据源 ,这里可以是mysql或者oracle的数据源都可以 + private JdbcTemplate jdbcTemplate = new JdbcTemplate(null); + public List query(){ + String sql = "select * from t_member"; + + return jdbcTemplate.executeQuery(sql, new RowMapper() { + @Override + public Merber mapRow(ResultSet rs, int rownum) throws Exception { + Merber merber = new Merber(); + merber.setUserName(rs.getString("username")); + merber.setPassword(rs.getString("password")); + merber.setNickName(rs.getString("nickname")); + merber.setAge(rs.getInt("age")); + merber.setAddr(rs.getString("addr")); + return merber; + } + },null); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/template/RowMapper.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/template/RowMapper.java new file mode 100644 index 0000000..3418776 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/template/RowMapper.java @@ -0,0 +1,8 @@ +package com.funtl.spring.hello.moudule.template; + +import java.sql.ResultSet; + +//行的映射接口 ,把数据库一行映射为一个对象 +public interface RowMapper { + T mapRow(ResultSet rs, int rownum) throws Exception; +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/template/TemplateTest.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/template/TemplateTest.java new file mode 100644 index 0000000..61e9494 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/moudule/template/TemplateTest.java @@ -0,0 +1,17 @@ +package com.funtl.spring.hello.moudule.template; + +/** + * @PackgeName: com.funtl.spring.hello.moudule.template + * @ClassName: TemplateTest + * @Author: Administrator + * Date: 2020/1/1 0001 18:25 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: 模板方法测试 + */ +public class TemplateTest { + public static void main(String[] args) { + MerberDao merberDao = new MerberDao(); + merberDao.query(); + } +} From e8d1e36ef5f8ae533c2899074641e62a8f217456 Mon Sep 17 00:00:00 2001 From: gczhang-minhong <1207365364@qq.com> Date: Mon, 10 Feb 2020 09:09:03 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitattributes | 7 - .gitignore | 26 --- LICENSE | 201 ------------------ README.md | 2 - pom.xml | 174 --------------- .../funtl/spring/hello/thread/T1/Account.java | 52 +++++ .../com/funtl/spring/hello/thread/T1/T.java | 35 +++ .../hello/thread/T1/T1_WhatisThread.java | 53 +++++ .../hello/thread/T1/TestCountDownLatch.java | 45 ++++ .../src/main/resources/application.yml | 34 --- .../src/main/resources/bootstrap.properties | 2 +- .../src/main/resources/application.yml | 5 +- .../src/main/resources/application.yml | 46 ++-- .../src/main/resources/bootstrap.properties | 2 +- .../src/main/resources/application.yml | 20 -- .../main/resources/bootstrap-prod.properties | 2 +- .../src/main/resources/bootstrap.properties | 2 +- spring-security-oauth2/pom.xml | 2 +- .../spring-security-oauth2-resource/pom.xml | 11 + .../config/ResourceServerConfiguration.java | 4 +- .../controller/TbContentController.java | 6 + .../src/main/resources/application.yml | 9 +- .../spring-security-oauth2-server/pom.xml | 12 ++ .../AuthorizationServerConfiguration.java | 25 +++ .../config/WebSecurityConfiguration.java | 15 +- .../oauth2/server/domain/TbPermission.java | 7 +- .../src/main/resources/application.yml | 13 +- .../tk/mybatis/mapper/TbPermissionMapper.xml | 1 + 28 files changed, 308 insertions(+), 505 deletions(-) delete mode 100644 .gitattributes delete mode 100644 .gitignore delete mode 100644 LICENSE delete mode 100644 README.md delete mode 100644 pom.xml create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/thread/T1/Account.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/thread/T1/T.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/thread/T1/T1_WhatisThread.java create mode 100644 spring-boot-demo/src/main/java/com/funtl/spring/hello/thread/T1/TestCountDownLatch.java delete mode 100644 spring-cloud-alibaba-dubbo/spring-cloud-alibaba-dubbo-consumer/src/main/resources/application.yml delete mode 100644 spring-cloud-alibaba/spring-cloud-alibaba-provider/src/main/resources/application.yml diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index fe8cb01..0000000 --- a/.gitattributes +++ /dev/null @@ -1,7 +0,0 @@ -# Windows-specific files that require CRLF: -*.bat eol=crlf -*.txt eol=crlf - -# Unix-specific files that require LF: -*.java eol=lf -*.sh eol=lf \ No newline at end of file diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 87579e9..0000000 --- a/.gitignore +++ /dev/null @@ -1,26 +0,0 @@ -target/ -!.mvn/wrapper/maven-wrapper.jar - -## STS ## -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans - -## IntelliJ IDEA ## -.idea -*.iws -*.iml -*.ipr - -## JRebel ## -rebel.xml - -## MAC ## -.DS_Store - -## Other ## -logs/ -temp/ diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 261eeb9..0000000 --- a/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed 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. diff --git a/README.md b/README.md deleted file mode 100644 index 7272551..0000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# Spring Boot 教学案例 - diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 2f66c19..0000000 --- a/pom.xml +++ /dev/null @@ -1,174 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.1.6.RELEASE - - - - com.funtl - spring-boot-samples - 1.0.0-SNAPSHOT - pom - http://www.funtl.com - - - spring-boot-samples-dependencies - spring-boot-demo - spring-cloud-alibaba - spring-cloud-alibaba-dubbo - spring-security-oauth2 - - - - 1.8 - ${java.version} - ${java.version} - UTF-8 - UTF-8 - - - - - Apache 2.0 - https://www.apache.org/licenses/LICENSE-2.0.txt - - - - - - liwemin - Lusifer Lee - lee.lusifer@gmail.com - - - - - - - com.funtl - spring-boot-samples-dependencies - ${project.version} - pom - import - - - - - - - default - - true - - - 0.0.9 - - - - - io.spring.javaformat - spring-javaformat-maven-plugin - ${spring-javaformat.version} - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*Tests.java - - - **/Abstract*.java - - - file:/dev/./urandom - true - - - - - org.apache.maven.plugins - maven-enforcer-plugin - - - enforce-rules - - enforce - - - - - - commons-logging:*:* - - true - - - true - - - - - - org.apache.maven.plugins - maven-install-plugin - - true - - - - org.apache.maven.plugins - maven-javadoc-plugin - - true - - true - - - - - - - - - spring-milestone - Spring Milestone - https://repo.spring.io/milestone - - false - - - - spring-snapshot - Spring Snapshot - https://repo.spring.io/snapshot - - true - - - - - - - spring-milestone - Spring Milestone - https://repo.spring.io/milestone - - false - - - - spring-snapshot - Spring Snapshot - https://repo.spring.io/snapshot - - true - - - - diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/thread/T1/Account.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/thread/T1/Account.java new file mode 100644 index 0000000..51d88b6 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/thread/T1/Account.java @@ -0,0 +1,52 @@ +package com.funtl.spring.hello.thread.T1; + +import java.util.concurrent.TimeUnit; + +/** + * @PackgeName: com.funtl.spring.hello.thread.T1 + * @ClassName: Account + * @Author: Administrator + * Date: 2020/1/4 0004 20:17 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +public class Account { + String name; + double balance; + + public synchronized void set(String name, double balance) { + this.name = name; + + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + this.balance = balance; + } + + public synchronized double getBalance(String name) { + return this.balance; + } + + public static void main(String[] args) { + Account a = new Account(); + new Thread(() -> + a.set("zhangsan", 100.0)).start(); + + try { + TimeUnit.SECONDS.sleep(1); + } catch (InterruptedException e) { + e.printStackTrace(); + } + System.out.println(a.getBalance("zhangsan")); + + try { + TimeUnit.SECONDS.sleep(2); + } catch (InterruptedException e) { + e.printStackTrace(); + } + System.out.println(a.getBalance("zhangsan")); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/thread/T1/T.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/thread/T1/T.java new file mode 100644 index 0000000..9658d41 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/thread/T1/T.java @@ -0,0 +1,35 @@ +package com.funtl.spring.hello.thread.T1; + +import java.util.concurrent.TimeUnit; + +/** + * @PackgeName: com.funtl.spring.hello.thread.T1 + * @ClassName: T + * @Author: Administrator + * Date: 2020/1/4 0004 20:27 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +public class T { + synchronized void m(){ + System.out.println("m start"); + try { + TimeUnit.SECONDS.sleep(1); + } catch (InterruptedException e) { + e.printStackTrace(); + } + System.out.println("m end"); + } + + public static void main(String[] args) { + new TT().m(); + } + static class TT extends T{ + synchronized void m(){ + System.out.println("child m start"); + super.m(); + System.out.println("child m end"); + } + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/thread/T1/T1_WhatisThread.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/thread/T1/T1_WhatisThread.java new file mode 100644 index 0000000..93fe4e9 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/thread/T1/T1_WhatisThread.java @@ -0,0 +1,53 @@ +package com.funtl.spring.hello.thread.T1; + +import java.util.concurrent.*; + +/** + * @PackgeName: com.funtl.spring.hello.thread.T1 + * @ClassName: T1 + * @Author: Administrator + * Date: 2020/1/4 0004 19:39 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +public class T1_WhatisThread { + private static class Mythread extends Thread { + public void run() { + System.out.println("hello myThread"); + } + } + + static class MyRun implements Runnable { + @Override + public void run() { + System.out.println("hello my run"); + } + } + + static class MyCall implements Callable { + + @Override + public String call() throws Exception { + System.out.println("hello MyCall"); + return "success"; + } + } + + + public static void main(String[] args) { + new Mythread().start(); + new Thread(new MyRun()).start(); + new Thread(() -> { + System.out.println("hello lambda"); + }).start(); + Thread t = new Thread(new FutureTask(new MyCall())); + t.start(); + + ExecutorService service = Executors.newCachedThreadPool(); + service.execute(() -> { + System.out.println("hello Threadpool"); + }); + service.shutdown(); + } +} diff --git a/spring-boot-demo/src/main/java/com/funtl/spring/hello/thread/T1/TestCountDownLatch.java b/spring-boot-demo/src/main/java/com/funtl/spring/hello/thread/T1/TestCountDownLatch.java new file mode 100644 index 0000000..4fa5846 --- /dev/null +++ b/spring-boot-demo/src/main/java/com/funtl/spring/hello/thread/T1/TestCountDownLatch.java @@ -0,0 +1,45 @@ +package com.funtl.spring.hello.thread.T1; + +import java.util.concurrent.CountDownLatch; + +/** + * @PackgeName: com.funtl.spring.hello.thread.T1 + * @ClassName: TestCountDownLatch + * @Author: Administrator + * Date: 2020/1/6 0006 21:51 + * project name: spring-boot-alibaba-samples + * @Version: + * @Description: + */ +public class TestCountDownLatch { + private static void CountDownLatch() { + Thread[] threads = new Thread[100]; + CountDownLatch countDownLatch = new CountDownLatch(threads.length); + + for (int i = 0; i < threads.length; i++) { + threads[i] = new Thread(() -> { + int result = 0; + for (int j = 0; j < 10000; j++) { + result += j; + } + countDownLatch.countDown(); + System.out.println("count"+countDownLatch.getCount()); + }); + } + + for (int i = 0; i < threads.length; i++) { + threads[i].start(); + } + + try { + countDownLatch.await(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + System.out.println("end latch"); + } + + public static void main(String[] args) { + CountDownLatch(); + } +} diff --git a/spring-cloud-alibaba-dubbo/spring-cloud-alibaba-dubbo-consumer/src/main/resources/application.yml b/spring-cloud-alibaba-dubbo/spring-cloud-alibaba-dubbo-consumer/src/main/resources/application.yml deleted file mode 100644 index ce0a98b..0000000 --- a/spring-cloud-alibaba-dubbo/spring-cloud-alibaba-dubbo-consumer/src/main/resources/application.yml +++ /dev/null @@ -1,34 +0,0 @@ -spring: - application: - name: dubbo-consumer - main: - allow-bean-definition-overriding: true - -dubbo: - scan: - base-packages: com.funtl.spring.cloud.alibaba.dubbo.controller - protocol: - name: dubbo - port: -1 - serialization: kryo - registry: - address: nacos://192.168.141.132:8848 -server: - port: 8080 - -endpoints: - dubbo: - enabled: true -management: - health: - dubbo: - status: - defaults: memory - extras: threadpool - endpoints: - web: - exposure: - include: "*" - -user: - name: "唯我成幸" \ No newline at end of file diff --git a/spring-cloud-alibaba-dubbo/spring-cloud-alibaba-dubbo-consumer/src/main/resources/bootstrap.properties b/spring-cloud-alibaba-dubbo/spring-cloud-alibaba-dubbo-consumer/src/main/resources/bootstrap.properties index c711e2a..121ef33 100644 --- a/spring-cloud-alibaba-dubbo/spring-cloud-alibaba-dubbo-consumer/src/main/resources/bootstrap.properties +++ b/spring-cloud-alibaba-dubbo/spring-cloud-alibaba-dubbo-consumer/src/main/resources/bootstrap.properties @@ -1,3 +1,3 @@ spring.application.name=dubbo-consumer-config -spring.cloud.nacos.config.server-addr=192.168.141.132:8848 +spring.cloud.nacos.config.server-addr=129.211.60.191:8848 spring.cloud.nacos.config.file-extension=yaml \ No newline at end of file diff --git a/spring-cloud-alibaba-dubbo/spring-cloud-alibaba-dubbo-provider/spring-cloud-alibaba-dubbo-provider-service/src/main/resources/application.yml b/spring-cloud-alibaba-dubbo/spring-cloud-alibaba-dubbo-provider/spring-cloud-alibaba-dubbo-provider-service/src/main/resources/application.yml index 2745acc..7c09023 100644 --- a/spring-cloud-alibaba-dubbo/spring-cloud-alibaba-dubbo-provider/spring-cloud-alibaba-dubbo-provider-service/src/main/resources/application.yml +++ b/spring-cloud-alibaba-dubbo/spring-cloud-alibaba-dubbo-provider/spring-cloud-alibaba-dubbo-provider-service/src/main/resources/application.yml @@ -9,9 +9,10 @@ dubbo: base-packages: com.funtl.spring.cloud.alibaba.dubbo.provider.service protocol: name: dubbo - port: -1 + port: 20881 serialization: kryo registry: - address: nacos://192.168.141.132:8848 + port: 8848 + address: nacos://129.211.60.191 provider: loadbalance: roundrobin \ No newline at end of file diff --git a/spring-cloud-alibaba/spring-cloud-alibaba-consumer/src/main/resources/application.yml b/spring-cloud-alibaba/spring-cloud-alibaba-consumer/src/main/resources/application.yml index 75de239..886bfab 100644 --- a/spring-cloud-alibaba/spring-cloud-alibaba-consumer/src/main/resources/application.yml +++ b/spring-cloud-alibaba/spring-cloud-alibaba-consumer/src/main/resources/application.yml @@ -1,23 +1,23 @@ -spring: - application: - # 服务名 - name: service-consumer - cloud: - nacos: - discovery: - # 服务注册中心 - server-addr: 192.168.141.132:8848 - -server: - # 服务端口 - port: 8080 - -management: - # 端点检查(健康检查) - endpoints: - web: - exposure: - include: "*" - -user: - name: "灶门炭治郎" \ No newline at end of file +#spring: +# application: +# # 服务名 +# name: service-consumer +# cloud: +# nacos: +# discovery: +# # 服务注册中心 +# server-addr: 129.211.60.191:8848 +# +#server: +# # 服务端口 +# port: 8080 +# +#management: +# # 端点检查(健康检查) +# endpoints: +# web: +# exposure: +# include: "*" +# +#user: +# name: "灶门炭治郎" \ No newline at end of file diff --git a/spring-cloud-alibaba/spring-cloud-alibaba-consumer/src/main/resources/bootstrap.properties b/spring-cloud-alibaba/spring-cloud-alibaba-consumer/src/main/resources/bootstrap.properties index 25d32f1..3a6cfd7 100644 --- a/spring-cloud-alibaba/spring-cloud-alibaba-consumer/src/main/resources/bootstrap.properties +++ b/spring-cloud-alibaba/spring-cloud-alibaba-consumer/src/main/resources/bootstrap.properties @@ -1,3 +1,3 @@ spring.application.name=service-consumer-config -spring.cloud.nacos.config.server-addr=192.168.141.132:8848 +spring.cloud.nacos.config.server-addr=129.211.60.191:8848 spring.cloud.nacos.config.file-extension=yaml \ No newline at end of file diff --git a/spring-cloud-alibaba/spring-cloud-alibaba-provider/src/main/resources/application.yml b/spring-cloud-alibaba/spring-cloud-alibaba-provider/src/main/resources/application.yml deleted file mode 100644 index 68f53d3..0000000 --- a/spring-cloud-alibaba/spring-cloud-alibaba-provider/src/main/resources/application.yml +++ /dev/null @@ -1,20 +0,0 @@ -spring: - application: - # 服务名 - name: service-provider - cloud: - nacos: - discovery: - # 服务注册中心 - server-addr: 192.168.141.132:8848 - -server: - # 服务端口 - port: 8070 - -management: - # 端点检查(健康检查) - endpoints: - web: - exposure: - include: "*" \ No newline at end of file diff --git a/spring-cloud-alibaba/spring-cloud-alibaba-provider/src/main/resources/bootstrap-prod.properties b/spring-cloud-alibaba/spring-cloud-alibaba-provider/src/main/resources/bootstrap-prod.properties index 187af2c..7fb43a7 100644 --- a/spring-cloud-alibaba/spring-cloud-alibaba-provider/src/main/resources/bootstrap-prod.properties +++ b/spring-cloud-alibaba/spring-cloud-alibaba-provider/src/main/resources/bootstrap-prod.properties @@ -1,4 +1,4 @@ spring.profiles.active=prod spring.application.name=service-provider-config -spring.cloud.nacos.config.server-addr=192.168.141.132:8848 +spring.cloud.nacos.config.server-addr=129.211.60.191:8848 spring.cloud.nacos.config.file-extension=yaml \ No newline at end of file diff --git a/spring-cloud-alibaba/spring-cloud-alibaba-provider/src/main/resources/bootstrap.properties b/spring-cloud-alibaba/spring-cloud-alibaba-provider/src/main/resources/bootstrap.properties index 40e61b4..4aab230 100644 --- a/spring-cloud-alibaba/spring-cloud-alibaba-provider/src/main/resources/bootstrap.properties +++ b/spring-cloud-alibaba/spring-cloud-alibaba-provider/src/main/resources/bootstrap.properties @@ -1,3 +1,3 @@ spring.application.name=service-provider-config -spring.cloud.nacos.config.server-addr=192.168.141.132:8848 +spring.cloud.nacos.config.server-addr=129.211.60.191:8848 spring.cloud.nacos.config.file-extension=yaml \ No newline at end of file diff --git a/spring-security-oauth2/pom.xml b/spring-security-oauth2/pom.xml index 2056546..63f40d9 100644 --- a/spring-security-oauth2/pom.xml +++ b/spring-security-oauth2/pom.xml @@ -10,7 +10,7 @@ spring-security-oauth2 - pom + war http://www.funtl.com diff --git a/spring-security-oauth2/spring-security-oauth2-resource/pom.xml b/spring-security-oauth2/spring-security-oauth2-resource/pom.xml index 4625cf4..34d4fb1 100644 --- a/spring-security-oauth2/spring-security-oauth2-resource/pom.xml +++ b/spring-security-oauth2/spring-security-oauth2-resource/pom.xml @@ -42,6 +42,17 @@ org.springframework.cloud spring-cloud-starter-oauth2 + + + org.springframework.security.oauth.boot + spring-security-oauth2-autoconfigure + + + + + org.springframework.security.oauth.boot + spring-security-oauth2-autoconfigure + 2.1.0.RELEASE diff --git a/spring-security-oauth2/spring-security-oauth2-resource/src/main/java/com/funtl/oauth2/resource/config/ResourceServerConfiguration.java b/spring-security-oauth2/spring-security-oauth2-resource/src/main/java/com/funtl/oauth2/resource/config/ResourceServerConfiguration.java index 4e7f142..79579d3 100644 --- a/spring-security-oauth2/spring-security-oauth2-resource/src/main/java/com/funtl/oauth2/resource/config/ResourceServerConfiguration.java +++ b/spring-security-oauth2/spring-security-oauth2-resource/src/main/java/com/funtl/oauth2/resource/config/ResourceServerConfiguration.java @@ -14,8 +14,7 @@ public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter @Override public void configure(HttpSecurity http) throws Exception { - http - .exceptionHandling() + http.formLogin().and().exceptionHandling() .and() .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) .and() @@ -27,4 +26,5 @@ public void configure(HttpSecurity http) throws Exception { .antMatchers("/delete/**").hasAuthority("SystemContentDelete"); } + } diff --git a/spring-security-oauth2/spring-security-oauth2-resource/src/main/java/com/funtl/oauth2/resource/controller/TbContentController.java b/spring-security-oauth2/spring-security-oauth2-resource/src/main/java/com/funtl/oauth2/resource/controller/TbContentController.java index f9b7494..604ab31 100644 --- a/spring-security-oauth2/spring-security-oauth2-resource/src/main/java/com/funtl/oauth2/resource/controller/TbContentController.java +++ b/spring-security-oauth2/spring-security-oauth2-resource/src/main/java/com/funtl/oauth2/resource/controller/TbContentController.java @@ -5,6 +5,7 @@ import com.funtl.oauth2.resource.service.TbContentService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -26,6 +27,7 @@ public class TbContentController { * * @return */ +// @PreAuthorize("hasAuthority('SystemContent')") @GetMapping("/") public ResponseResult> selectAll() { return new ResponseResult<>(Integer.valueOf(HttpStatus.OK.value()), HttpStatus.OK.toString(), tbContentService.selectAll()); @@ -37,6 +39,7 @@ public ResponseResult> selectAll() { * @param id * @return */ +// @PreAuthorize("hasAuthority('SystemContentView')") @GetMapping("/view/{id}") public ResponseResult getById(@PathVariable Long id) { return new ResponseResult<>(Integer.valueOf(HttpStatus.OK.value()), HttpStatus.OK.toString(), tbContentService.getById(id)); @@ -48,6 +51,7 @@ public ResponseResult getById(@PathVariable Long id) { * @param tbContent * @return */ +// @PreAuthorize("hasAuthority('SystemContentInsert')") @PostMapping("/insert") public ResponseResult insert(@RequestBody TbContent tbContent) { int count = tbContentService.insert(tbContent); @@ -65,6 +69,7 @@ public ResponseResult insert(@RequestBody TbContent tbContent) { * @param tbContent * @return */ +// @PreAuthorize("hasAuthority('SystemContentUpdate')") @PutMapping("/update") public ResponseResult update(@RequestBody TbContent tbContent) { int count = tbContentService.update(tbContent); @@ -82,6 +87,7 @@ public ResponseResult update(@RequestBody TbContent tbContent) { * @param id * @return */ +// @PreAuthorize("hasAuthority('SystemContentDelete')") @DeleteMapping("/delete/{id}") public ResponseResult delete(@PathVariable Long id) { int count = tbContentService.delete(id); diff --git a/spring-security-oauth2/spring-security-oauth2-resource/src/main/resources/application.yml b/spring-security-oauth2/spring-security-oauth2-resource/src/main/resources/application.yml index 07f56a9..6774ea3 100644 --- a/spring-security-oauth2/spring-security-oauth2-resource/src/main/resources/application.yml +++ b/spring-security-oauth2/spring-security-oauth2-resource/src/main/resources/application.yml @@ -4,7 +4,7 @@ spring: datasource: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://192.168.141.128:3307/oauth2_resource?useUnicode=true&characterEncoding=utf-8&useSSL=false + url: jdbc:mysql://129.211.60.191:3306/oauth2_resource?useUnicode=true&characterEncoding=utf-8&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC username: root password: 123456 hikari: @@ -20,8 +20,8 @@ spring: security: oauth2: client: - client-id: client - client-secret: secret + client-id: 3cc2ecb1331b1c5623ba + client-secret: c21e3c6271b23a0b59c0d0de09c9ae7ed17c82e1 access-token-uri: http://localhost:8080/oauth/token user-authorization-uri: http://localhost:8080/oauth/authorize resource: @@ -34,8 +34,7 @@ server: mybatis: type-aliases-package: com.funtl.oauth2.resource.domain - mapper-locations: classpath:mapper/*.xml - + mapper-locations: classpath:tk/mybatis/mapper/*.xml logging: level: root: INFO diff --git a/spring-security-oauth2/spring-security-oauth2-server/pom.xml b/spring-security-oauth2/spring-security-oauth2-server/pom.xml index 5948fc2..0bb0df1 100644 --- a/spring-security-oauth2/spring-security-oauth2-server/pom.xml +++ b/spring-security-oauth2/spring-security-oauth2-server/pom.xml @@ -11,6 +11,7 @@ spring-security-oauth2-server http://www.funtl.com + war @@ -42,6 +43,17 @@ org.springframework.cloud spring-cloud-starter-oauth2 + + + org.springframework.security.oauth.boot + spring-security-oauth2-autoconfigure + + + + + org.springframework.security.oauth.boot + spring-security-oauth2-autoconfigure + 2.1.0.RELEASE diff --git a/spring-security-oauth2/spring-security-oauth2-server/src/main/java/com/funtl/oauth2/server/config/AuthorizationServerConfiguration.java b/spring-security-oauth2/spring-security-oauth2-server/src/main/java/com/funtl/oauth2/server/config/AuthorizationServerConfiguration.java index d601b11..545d3da 100644 --- a/spring-security-oauth2/spring-security-oauth2-server/src/main/java/com/funtl/oauth2/server/config/AuthorizationServerConfiguration.java +++ b/spring-security-oauth2/spring-security-oauth2-server/src/main/java/com/funtl/oauth2/server/config/AuthorizationServerConfiguration.java @@ -1,18 +1,22 @@ package com.funtl.oauth2.server.config; +import org.springframework.beans.factory.annotation.Autowired; 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.security.authentication.AuthenticationManager; 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.ClientDetailsService; import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService; import org.springframework.security.oauth2.provider.token.TokenStore; import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore; +import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore; import javax.sql.DataSource; @@ -20,6 +24,12 @@ @EnableAuthorizationServer public class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter { + /** + * 注入用于支持 password 模式 + */ + @Autowired + private AuthenticationManager authenticationManager; + @Bean @Primary @ConfigurationProperties(prefix = "spring.datasource") @@ -44,6 +54,8 @@ public ClientDetailsService jdbcClientDetails() { public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { // 设置令牌 endpoints.tokenStore(tokenStore()); + endpoints.authenticationManager(authenticationManager); // 开启密码验证,来源于 WebSecurityConfigurerAdapter + } @Override @@ -51,4 +63,17 @@ public void configure(ClientDetailsServiceConfigurer clients) throws Exception { // 读取客户端配置 clients.withClientDetails(jdbcClientDetails()); } + +// /** +// * 声明安全约束,哪些允许访问,哪些不允许访问 +// * +// * @param oauthServer +// */ +// @Override +// public void configure(AuthorizationServerSecurityConfigurer oauthServer) { +// // 对于CheckEndpoint控制器[框架自带的校验]的/oauth/check端点允许所有客户端发送器请求而不会被Spring-security拦截 +// oauthServer.tokenKeyAccess("permitAll()").checkTokenAccess("isAuthenticated()"); +// // 此处可添加自定义过滤器,对oauth相关的请求做进一步处理 +// // oauthServer.addTokenEndpointAuthenticationFilter(new Oauth2Filter()); +// } } diff --git a/spring-security-oauth2/spring-security-oauth2-server/src/main/java/com/funtl/oauth2/server/config/WebSecurityConfiguration.java b/spring-security-oauth2/spring-security-oauth2-server/src/main/java/com/funtl/oauth2/server/config/WebSecurityConfiguration.java index 81adef0..f8e17d9 100644 --- a/spring-security-oauth2/spring-security-oauth2-server/src/main/java/com/funtl/oauth2/server/config/WebSecurityConfiguration.java +++ b/spring-security-oauth2/spring-security-oauth2-server/src/main/java/com/funtl/oauth2/server/config/WebSecurityConfiguration.java @@ -3,6 +3,7 @@ import com.funtl.oauth2.server.config.service.UserDetailsServiceImpl; 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.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.web.builders.WebSecurity; @@ -21,7 +22,17 @@ public BCryptPasswordEncoder passwordEncoder() { // 设置默认的加密方式 return new BCryptPasswordEncoder(); } - + /** + * 用于支持 password 模式 + * + * @return + * @throws Exception + */ + @Bean + @Override + public AuthenticationManager authenticationManagerBean() throws Exception { + return super.authenticationManagerBean(); + } @Bean @Override public UserDetailsService userDetailsService() { @@ -39,4 +50,6 @@ public void configure(WebSecurity web) throws Exception { // 将 check_token 暴露出去,否则资源服务器访问时报 403 错误 web.ignoring().antMatchers("/oauth/check_token"); } + + } diff --git a/spring-security-oauth2/spring-security-oauth2-server/src/main/java/com/funtl/oauth2/server/domain/TbPermission.java b/spring-security-oauth2/spring-security-oauth2-server/src/main/java/com/funtl/oauth2/server/domain/TbPermission.java index 7ca0934..4359192 100644 --- a/spring-security-oauth2/spring-security-oauth2-server/src/main/java/com/funtl/oauth2/server/domain/TbPermission.java +++ b/spring-security-oauth2/spring-security-oauth2-server/src/main/java/com/funtl/oauth2/server/domain/TbPermission.java @@ -34,13 +34,18 @@ public class TbPermission implements Serializable { */ @Column(name = "`enname`") private String enname; - + /** + * url回调地址 + */ + @Column(name = "url") + private String url; /** * 备注 */ @Column(name = "description") private String description; + @Column(name = "created") private Date created; diff --git a/spring-security-oauth2/spring-security-oauth2-server/src/main/resources/application.yml b/spring-security-oauth2/spring-security-oauth2-server/src/main/resources/application.yml index 264a5c9..d994753 100644 --- a/spring-security-oauth2/spring-security-oauth2-server/src/main/resources/application.yml +++ b/spring-security-oauth2/spring-security-oauth2-server/src/main/resources/application.yml @@ -4,7 +4,7 @@ spring: datasource: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.cj.jdbc.Driver - jdbc-url: jdbc:mysql://192.168.141.128:3307/oauth2?useUnicode=true&characterEncoding=utf-8&useSSL=false + jdbc-url: jdbc:mysql://129.211.60.191:3306/oauth2?useUnicode=true&characterEncoding=utf-8&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC username: root password: 123456 hikari: @@ -21,5 +21,14 @@ server: port: 8080 mybatis: + configuration: + map-underscore-to-camel-case: true type-aliases-package: com.funtl.oauth2.server.domain - mapper-locations: classpath:mapper/*.xml \ No newline at end of file + mapper-locations: classpath:tk/mybatis/mapper/*.xml + +logging: + level: + root: INFO + org.springframework.web: INFO + org.springframework.security: INFO + org.springframework.security.oauth2: INFO diff --git a/spring-security-oauth2/spring-security-oauth2-server/src/main/resources/tk/mybatis/mapper/TbPermissionMapper.xml b/spring-security-oauth2/spring-security-oauth2-server/src/main/resources/tk/mybatis/mapper/TbPermissionMapper.xml index 30a461a..78b517d 100644 --- a/spring-security-oauth2/spring-security-oauth2-server/src/main/resources/tk/mybatis/mapper/TbPermissionMapper.xml +++ b/spring-security-oauth2/spring-security-oauth2-server/src/main/resources/tk/mybatis/mapper/TbPermissionMapper.xml @@ -7,6 +7,7 @@ + From 53b48680be4d020b72813f95686e09ac2c350df0 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 27 Jun 2020 14:42:10 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application.yml | 4 ++-- .../tests/ShardingSphereTests.java | 4 ++-- .../SeataBusinessTransactionController.java | 2 +- .../src/main/resources/application.yml | 6 +++--- .../src/main/resources/application.yml | 20 +++++++++++++++---- .../src/main/resources/file.conf | 2 +- .../src/main/resources/application.yml | 8 ++++---- .../src/main/resources/file.conf | 2 +- .../src/main/resources/application.yml | 6 +++--- .../src/main/resources/file.conf | 2 +- .../src/main/resources/application.yml | 4 ++-- 11 files changed, 36 insertions(+), 24 deletions(-) diff --git a/apache-shardingsphere/sharding-jdbc/src/main/resources/application.yml b/apache-shardingsphere/sharding-jdbc/src/main/resources/application.yml index 9747206..b69931d 100644 --- a/apache-shardingsphere/sharding-jdbc/src/main/resources/application.yml +++ b/apache-shardingsphere/sharding-jdbc/src/main/resources/application.yml @@ -12,7 +12,7 @@ spring: ds0: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.jdbc.Driver - jdbc-url: jdbc:mysql://192.168.2.121:3310/myshop_0?useUnicode=true&characterEncoding=utf-8&serverTimezone=Hongkong&useSSL=false + jdbc-url: jdbc:mysql://129.211.60.191:3306/myshop_0?useUnicode=true&characterEncoding=utf-8&serverTimezone=Hongkong&useSSL=false username: root password: '123456' hikari: @@ -27,7 +27,7 @@ spring: ds1: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.jdbc.Driver - jdbc-url: jdbc:mysql://192.168.2.121:3311/myshop_1?useUnicode=true&characterEncoding=utf-8&serverTimezone=Hongkong&useSSL=false + jdbc-url: jdbc:mysql://129.211.60.191:3306/myshop_1?useUnicode=true&characterEncoding=utf-8&serverTimezone=Hongkong&useSSL=false username: root password: '123456' hikari: diff --git a/apache-shardingsphere/sharding-jdbc/src/test/java/com/funtl/apache/shardingsphere/tests/ShardingSphereTests.java b/apache-shardingsphere/sharding-jdbc/src/test/java/com/funtl/apache/shardingsphere/tests/ShardingSphereTests.java index 554f85b..2eaa73e 100644 --- a/apache-shardingsphere/sharding-jdbc/src/test/java/com/funtl/apache/shardingsphere/tests/ShardingSphereTests.java +++ b/apache-shardingsphere/sharding-jdbc/src/test/java/com/funtl/apache/shardingsphere/tests/ShardingSphereTests.java @@ -25,8 +25,8 @@ public class ShardingSphereTests { @Test public void testInsertOrder() { TbOrder tbOrder = new TbOrder(); - tbOrder.setOrderId(1L); - tbOrder.setUserId(1L); + tbOrder.setOrderId(3L); + tbOrder.setUserId(2L); tbOrderMapper.insert(tbOrder); } diff --git a/spring-cloud-alibaba-seata/seata-business/seata-business-transaction-service/src/main/java/com/funtl/spring/cloud/alibaba/seata/controller/SeataBusinessTransactionController.java b/spring-cloud-alibaba-seata/seata-business/seata-business-transaction-service/src/main/java/com/funtl/spring/cloud/alibaba/seata/controller/SeataBusinessTransactionController.java index 79b3f77..36d9c38 100644 --- a/spring-cloud-alibaba-seata/seata-business/seata-business-transaction-service/src/main/java/com/funtl/spring/cloud/alibaba/seata/controller/SeataBusinessTransactionController.java +++ b/spring-cloud-alibaba-seata/seata-business/seata-business-transaction-service/src/main/java/com/funtl/spring/cloud/alibaba/seata/controller/SeataBusinessTransactionController.java @@ -19,7 +19,7 @@ public class SeataBusinessTransactionController { public String createOrder() { TbOrder order = new TbOrder(); order.setOrderId(1); - order.setUserId(1L); + order.setUserId(2L); TbOrderItem orderItem = new TbOrderItem(); orderItem.setUserId(1L); diff --git a/spring-cloud-alibaba-seata/seata-business/seata-business-transaction-service/src/main/resources/application.yml b/spring-cloud-alibaba-seata/seata-business/seata-business-transaction-service/src/main/resources/application.yml index ead55f0..7a5a694 100644 --- a/spring-cloud-alibaba-seata/seata-business/seata-business-transaction-service/src/main/resources/application.yml +++ b/spring-cloud-alibaba-seata/seata-business/seata-business-transaction-service/src/main/resources/application.yml @@ -6,10 +6,10 @@ spring: cloud: nacos: discovery: - server-addr: 192.168.2.121:8848 + server-addr: 129.211.60.191:8848 sentinel: transport: - dashboard: localhost:8888 + dashboard: 129.211.60.191:8088 dubbo: scan: @@ -18,7 +18,7 @@ dubbo: name: dubbo port: -1 registry: - address: nacos://192.168.2.121:8848 + address: nacos://129.211.60.191:8848 server: port: 12001 diff --git a/spring-cloud-alibaba-seata/seata-provider/seata-provider-order-item-service/src/main/resources/application.yml b/spring-cloud-alibaba-seata/seata-provider/seata-provider-order-item-service/src/main/resources/application.yml index b0ad132..4ac8abd 100644 --- a/spring-cloud-alibaba-seata/seata-provider/seata-provider-order-item-service/src/main/resources/application.yml +++ b/spring-cloud-alibaba-seata/seata-provider/seata-provider-order-item-service/src/main/resources/application.yml @@ -1,3 +1,15 @@ +base: + config: + db: + hostname: 129.211.60.191 + port: 3306 + nacos: + hostname: 129.211.60.191 + port: 8848 + sentile: + hostname: 129.211.60.191 + port: 8088 + spring: main: allow-bean-definition-overriding: true @@ -6,17 +18,17 @@ spring: cloud: nacos: discovery: - server-addr: 192.168.2.121:8848 + server-addr: ${base.config.nacos.hostname}:${base.config.nacos.port} sentinel: transport: - dashboard: localhost:8888 + dashboard: ${base.config.sentile.hostname}:${base.config.sentile.port} alibaba: seata: tx-service-group: tx-group datasource: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.cj.jdbc.Driver - jdbc-url: jdbc:mysql://192.168.2.121:3346/db_order_item?useUnicode=true&characterEncoding=utf-8&serverTimezone=Hongkong&useSSL=false + jdbc-url: jdbc:mysql://129.211.60.191:3306/db_order_item?useUnicode=true&characterEncoding=utf-8&serverTimezone=Hongkong&useSSL=false username: root password: 123456 hikari: @@ -38,7 +50,7 @@ dubbo: provider: loadbalance: roundrobin registry: - address: nacos://192.168.2.121:8848 + address: nacos://129.211.60.191:8848 mybatis: type-aliases-package: com.funtl.spring.cloud.alibaba.provider.domain diff --git a/spring-cloud-alibaba-seata/seata-provider/seata-provider-order-item-service/src/main/resources/file.conf b/spring-cloud-alibaba-seata/seata-provider/seata-provider-order-item-service/src/main/resources/file.conf index a011e4d..1493607 100644 --- a/spring-cloud-alibaba-seata/seata-provider/seata-provider-order-item-service/src/main/resources/file.conf +++ b/spring-cloud-alibaba-seata/seata-provider/seata-provider-order-item-service/src/main/resources/file.conf @@ -22,7 +22,7 @@ transport { } service { vgroup_mapping.tx_group = "default" - default.grouplist = "192.168.2.121:8091" + default.grouplist = "129.211.60.191:8091" enableDegrade = false disableGlobalTransaction = false } diff --git a/spring-cloud-alibaba-seata/seata-provider/seata-provider-order-service/src/main/resources/application.yml b/spring-cloud-alibaba-seata/seata-provider/seata-provider-order-service/src/main/resources/application.yml index 2021246..77cd01a 100644 --- a/spring-cloud-alibaba-seata/seata-provider/seata-provider-order-service/src/main/resources/application.yml +++ b/spring-cloud-alibaba-seata/seata-provider/seata-provider-order-service/src/main/resources/application.yml @@ -6,17 +6,17 @@ spring: cloud: nacos: discovery: - server-addr: 192.168.2.121:8848 + server-addr: 129.211.60.191:8848 sentinel: transport: - dashboard: localhost:8888 + dashboard: 129.211.60.191:8088 alibaba: seata: tx-service-group: tx-group datasource: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.cj.jdbc.Driver - jdbc-url: jdbc:mysql://192.168.2.121:3336/db_order?useUnicode=true&characterEncoding=utf-8&serverTimezone=Hongkong&useSSL=false + jdbc-url: jdbc:mysql://129.211.60.191:3306/db_order?useUnicode=true&characterEncoding=utf-8&serverTimezone=Hongkong&useSSL=false username: root password: 123456 hikari: @@ -38,7 +38,7 @@ dubbo: provider: loadbalance: roundrobin registry: - address: nacos://192.168.2.121:8848 + address: nacos://129.211.60.191:8848 mybatis: type-aliases-package: com.funtl.spring.cloud.alibaba.provider.domain diff --git a/spring-cloud-alibaba-seata/seata-provider/seata-provider-order-service/src/main/resources/file.conf b/spring-cloud-alibaba-seata/seata-provider/seata-provider-order-service/src/main/resources/file.conf index a011e4d..1493607 100644 --- a/spring-cloud-alibaba-seata/seata-provider/seata-provider-order-service/src/main/resources/file.conf +++ b/spring-cloud-alibaba-seata/seata-provider/seata-provider-order-service/src/main/resources/file.conf @@ -22,7 +22,7 @@ transport { } service { vgroup_mapping.tx_group = "default" - default.grouplist = "192.168.2.121:8091" + default.grouplist = "129.211.60.191:8091" enableDegrade = false disableGlobalTransaction = false } diff --git a/spring-cloud-alibaba-seata/seata-provider/seata-provider-transaction-service/src/main/resources/application.yml b/spring-cloud-alibaba-seata/seata-provider/seata-provider-transaction-service/src/main/resources/application.yml index c89b8ed..a883bb8 100644 --- a/spring-cloud-alibaba-seata/seata-provider/seata-provider-transaction-service/src/main/resources/application.yml +++ b/spring-cloud-alibaba-seata/seata-provider/seata-provider-transaction-service/src/main/resources/application.yml @@ -6,10 +6,10 @@ spring: cloud: nacos: discovery: - server-addr: 192.168.2.121:8848 + server-addr: 129.211.60.191:8848 sentinel: transport: - dashboard: localhost:8888 + dashboard: 129.211.60.191:8088 alibaba: seata: tx-service-group: tx-group @@ -23,7 +23,7 @@ dubbo: provider: loadbalance: roundrobin registry: - address: nacos://192.168.2.121:8848 + address: nacos://129.211.60.191:8848 #logging: # level: diff --git a/spring-cloud-alibaba-seata/seata-provider/seata-provider-transaction-service/src/main/resources/file.conf b/spring-cloud-alibaba-seata/seata-provider/seata-provider-transaction-service/src/main/resources/file.conf index a011e4d..1493607 100644 --- a/spring-cloud-alibaba-seata/seata-provider/seata-provider-transaction-service/src/main/resources/file.conf +++ b/spring-cloud-alibaba-seata/seata-provider/seata-provider-transaction-service/src/main/resources/file.conf @@ -22,7 +22,7 @@ transport { } service { vgroup_mapping.tx_group = "default" - default.grouplist = "192.168.2.121:8091" + default.grouplist = "129.211.60.191:8091" enableDegrade = false disableGlobalTransaction = false } diff --git a/spring-security-oauth2/spring-security-oauth2-resource/src/main/resources/application.yml b/spring-security-oauth2/spring-security-oauth2-resource/src/main/resources/application.yml index 6774ea3..3a6c9e0 100644 --- a/spring-security-oauth2/spring-security-oauth2-resource/src/main/resources/application.yml +++ b/spring-security-oauth2/spring-security-oauth2-resource/src/main/resources/application.yml @@ -4,9 +4,9 @@ spring: datasource: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://129.211.60.191:3306/oauth2_resource?useUnicode=true&characterEncoding=utf-8&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC + url: jdbc:mysql://129.211.60.191:3307/oauth2_resource?useUnicode=true&characterEncoding=utf-8&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC username: root - password: 123456 + password: gczhang1233456minhong hikari: minimum-idle: 5 idle-timeout: 600000 From 4aaf93784d66c35d7e88423d94c4a9ec4732e706 Mon Sep 17 00:00:00 2001 From: gczhang-minhong <41230490+gczhang-minhong@users.noreply.github.com> Date: Sun, 28 Jun 2020 10:31:06 +0800 Subject: [PATCH 5/5] Create README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..27e57f2 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# spring-boot-samples +Spring Boot 教学案例