马府强
2 years ago
32 changed files with 549 additions and 1 deletions
@ -1,2 +1,133 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<module type="JAVA_MODULE" version="4" /> |
|||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> |
|||
<component name="FacetManager"> |
|||
<facet type="Spring" name="Spring"> |
|||
<configuration /> |
|||
</facet> |
|||
</component> |
|||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8"> |
|||
<output url="file://$MODULE_DIR$/target/classes" /> |
|||
<output-test url="file://$MODULE_DIR$/target/test-classes" /> |
|||
<content url="file://$MODULE_DIR$"> |
|||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> |
|||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> |
|||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> |
|||
<excludeFolder url="file://$MODULE_DIR$/target" /> |
|||
</content> |
|||
<orderEntry type="inheritedJdk" /> |
|||
<orderEntry type="sourceFolder" forTests="false" /> |
|||
<orderEntry type="library" name="Maven: org.springframework:spring-context:5.3.23" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.1.18.RELEASE" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.springframework:spring-core:5.1.18.RELEASE" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.1.18.RELEASE" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.springframework:spring-expression:5.1.18.RELEASE" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.3.22" level="project" /> |
|||
<orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.73" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-aop:2.1.17.RELEASE" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:2.1.17.RELEASE" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:2.1.17.RELEASE" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-logging:2.1.17.RELEASE" level="project" /> |
|||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.2.3" level="project" /> |
|||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.2.3" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-to-slf4j:2.11.2" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.11.2" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.slf4j:jul-to-slf4j:1.7.30" level="project" /> |
|||
<orderEntry type="library" name="Maven: javax.annotation:javax.annotation-api:1.3.2" level="project" /> |
|||
<orderEntry type="library" scope="RUNTIME" name="Maven: org.yaml:snakeyaml:1.23" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.aspectj:aspectjweaver:1.9.6" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-redis:2.1.3.RELEASE" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-keyvalue:2.1.20.RELEASE" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-commons:2.1.20.RELEASE" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.springframework:spring-tx:5.1.18.RELEASE" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.springframework:spring-oxm:5.1.18.RELEASE" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.springframework:spring-context-support:5.1.18.RELEASE" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.30" level="project" /> |
|||
<orderEntry type="library" name="Maven: commons-io:commons-io:2.5" level="project" /> |
|||
<orderEntry type="library" name="Maven: commons-fileupload:commons-fileupload:1.3.3" level="project" /> |
|||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.13" level="project" /> |
|||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" /> |
|||
<orderEntry type="library" name="Maven: com.alibaba:druid-spring-boot-starter:1.1.22" level="project" /> |
|||
<orderEntry type="library" name="Maven: com.alibaba:druid:1.1.22" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-autoconfigure:2.1.17.RELEASE" level="project" /> |
|||
<orderEntry type="library" name="Maven: com.github.penggle:kaptcha:2.3.2" level="project" /> |
|||
<orderEntry type="library" name="Maven: javax.servlet:javax.servlet-api:4.0.1" level="project" /> |
|||
<orderEntry type="library" name="Maven: com.jhlabs:filters:2.0.235-1" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.apache.shiro:shiro-core:1.6.0" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.apache.shiro:shiro-lang:1.6.0" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.apache.shiro:shiro-cache:1.6.0" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.apache.shiro:shiro-crypto-hash:1.6.0" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.apache.shiro:shiro-crypto-core:1.6.0" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.apache.shiro:shiro-crypto-cipher:1.6.0" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.apache.shiro:shiro-config-core:1.6.0" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.apache.shiro:shiro-config-ogdl:1.6.0" level="project" /> |
|||
<orderEntry type="library" name="Maven: commons-beanutils:commons-beanutils:1.9.4" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.apache.shiro:shiro-event:1.6.0" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.apache.shiro:shiro-spring:1.6.0" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.apache.shiro:shiro-web:1.6.0" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.owasp.encoder:encoder:1.2.2" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.apache.shiro:shiro-ehcache:1.6.0" level="project" /> |
|||
<orderEntry type="library" name="Maven: net.sf.ehcache:ehcache-core:2.6.11" level="project" /> |
|||
<orderEntry type="library" name="Maven: com.github.theborakompanioni:thymeleaf-extras-shiro:2.0.0" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.springframework:spring-web:5.1.18.RELEASE" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.8.1" level="project" /> |
|||
<orderEntry type="library" name="Maven: eu.bitwalker:UserAgentUtils:1.19" level="project" /> |
|||
<orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper-spring-boot-starter:1.2.5" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.2" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-jdbc:2.1.17.RELEASE" level="project" /> |
|||
<orderEntry type="library" name="Maven: com.zaxxer:HikariCP:3.2.0" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.springframework:spring-jdbc:5.1.18.RELEASE" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-autoconfigure:1.3.2" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.mybatis:mybatis:3.4.6" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.mybatis:mybatis-spring:1.3.2" level="project" /> |
|||
<orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper-spring-boot-autoconfigure:1.2.5" level="project" /> |
|||
<orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper:5.1.4" level="project" /> |
|||
<orderEntry type="library" name="Maven: com.github.jsqlparser:jsqlparser:1.0" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.apache.commons:commons-pool2:2.9.0" level="project" /> |
|||
<orderEntry type="library" name="Maven: io.netty:netty-all:4.0.24.Final" level="project" /> |
|||
<orderEntry type="library" name="Maven: com.github.oshi:oshi-core:5.2.5" level="project" /> |
|||
<orderEntry type="library" name="Maven: net.java.dev.jna:jna:4.5.2" level="project" /> |
|||
<orderEntry type="library" name="Maven: net.java.dev.jna:jna-platform:4.5.2" level="project" /> |
|||
<orderEntry type="library" name="Maven: io.springfox:springfox-swagger2:2.9.2" level="project" /> |
|||
<orderEntry type="library" name="Maven: io.springfox:springfox-spi:2.9.2" level="project" /> |
|||
<orderEntry type="library" name="Maven: io.springfox:springfox-core:2.9.2" level="project" /> |
|||
<orderEntry type="library" name="Maven: net.bytebuddy:byte-buddy:1.9.16" level="project" /> |
|||
<orderEntry type="library" name="Maven: io.springfox:springfox-schema:2.9.2" level="project" /> |
|||
<orderEntry type="library" name="Maven: io.springfox:springfox-swagger-common:2.9.2" level="project" /> |
|||
<orderEntry type="library" name="Maven: io.springfox:springfox-spring-web:2.9.2" level="project" /> |
|||
<orderEntry type="library" name="Maven: com.google.guava:guava:20.0" level="project" /> |
|||
<orderEntry type="library" name="Maven: com.fasterxml:classmate:1.4.0" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.springframework.plugin:spring-plugin-core:1.2.0.RELEASE" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.springframework.plugin:spring-plugin-metadata:1.2.0.RELEASE" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.mapstruct:mapstruct:1.2.0.Final" level="project" /> |
|||
<orderEntry type="library" name="Maven: io.springfox:springfox-swagger-ui:2.9.2" level="project" /> |
|||
<orderEntry type="library" name="Maven: com.github.xiaoymin:swagger-bootstrap-ui:1.8.9" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.apache.poi:poi-ooxml:3.17" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.apache.poi:poi:3.17" level="project" /> |
|||
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.11" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.apache.commons:commons-collections4:4.1" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.apache.poi:poi-ooxml-schemas:3.17" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.apache.xmlbeans:xmlbeans:2.6.0" level="project" /> |
|||
<orderEntry type="library" name="Maven: stax:stax-api:1.0.1" level="project" /> |
|||
<orderEntry type="library" name="Maven: com.github.virtuald:curvesapi:1.04" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.apache.velocity:velocity:1.7" level="project" /> |
|||
<orderEntry type="library" name="Maven: commons-collections:commons-collections:3.2.1" level="project" /> |
|||
<orderEntry type="library" name="Maven: commons-lang:commons-lang:2.4" level="project" /> |
|||
<orderEntry type="library" name="Maven: us.codecraft:webmagic-core:0.7.3" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.12" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.13" level="project" /> |
|||
<orderEntry type="library" name="Maven: us.codecraft:xsoup:0.3.1" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.assertj:assertj-core:3.11.1" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-log4j12:1.7.30" level="project" /> |
|||
<orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.jsoup:jsoup:1.10.3" level="project" /> |
|||
<orderEntry type="library" name="Maven: com.jayway.jsonpath:json-path:2.4.0" level="project" /> |
|||
<orderEntry type="library" name="Maven: net.minidev:json-smart:2.3" level="project" /> |
|||
<orderEntry type="library" name="Maven: net.minidev:accessors-smart:1.2" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.ow2.asm:asm:5.0.4" level="project" /> |
|||
<orderEntry type="library" name="Maven: us.codecraft:webmagic-extension:0.7.3" level="project" /> |
|||
<orderEntry type="library" name="Maven: redis.clients:jedis:2.9.3" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.bouncycastle:bcprov-jdk15on:1.67" level="project" /> |
|||
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.6" level="project" /> |
|||
<orderEntry type="library" name="Maven: org.projectlombok:lombok:1.18.12" level="project" /> |
|||
</component> |
|||
</module> |
@ -0,0 +1,70 @@ |
|||
package org.example.haoshi; |
|||
|
|||
|
|||
import org.springframework.util.StopWatch; |
|||
|
|||
import java.util.concurrent.TimeUnit; |
|||
|
|||
/** |
|||
* 使用 StopWatch 优雅打印执行耗时 |
|||
* |
|||
* @author xiaomage |
|||
* @date 2022/12/24 |
|||
*/ |
|||
public class StopWatchTest { |
|||
|
|||
|
|||
public static void main(String[] args) throws InterruptedException { |
|||
|
|||
|
|||
// long start = System.currentTimeMillis();
|
|||
// // do something
|
|||
// Thread.sleep(100);
|
|||
// long end = System.currentTimeMillis();
|
|||
// long start2 = System.currentTimeMillis();
|
|||
// // do something
|
|||
// Thread.sleep(200);
|
|||
// long end2 = System.currentTimeMillis();
|
|||
// System.out.println("某某1执行耗时:" + (end - start));
|
|||
// System.out.println("某某2执行耗时:" + (end2 - start2));
|
|||
|
|||
|
|||
// StopWatch sw = new StopWatch();
|
|||
// sw.start();
|
|||
// Thread.sleep(1000);
|
|||
// sw.stop();
|
|||
// System.out.println(sw.getTotalTimeMillis());
|
|||
|
|||
|
|||
StopWatch sw = new StopWatch(); |
|||
sw.start("A"); |
|||
Thread.sleep(500); |
|||
sw.stop(); |
|||
sw.start("B"); |
|||
Thread.sleep(300); |
|||
sw.stop(); |
|||
sw.start("C"); |
|||
Thread.sleep(200); |
|||
sw.stop(); |
|||
System.out.println(sw.prettyPrint()); |
|||
|
|||
// 一个StopWatch实例一次只能开启一个task,不能同时start多个task,
|
|||
// 并且在该task未stop之前不能start一个新的task,
|
|||
// 必须在该task stop之后才能开启新的task,若要一次开启多个,需要new不同的StopWatch实例;
|
|||
} |
|||
|
|||
private static void getTasksTime() throws InterruptedException { |
|||
StopWatch sw = new StopWatch(); |
|||
sw.start("A"); |
|||
Thread.sleep(500); |
|||
sw.stop(); |
|||
sw.start("B"); |
|||
Thread.sleep(300); |
|||
sw.stop(); |
|||
sw.start("C"); |
|||
Thread.sleep(200); |
|||
sw.stop(); |
|||
System.out.println(sw.prettyPrint()); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,17 @@ |
|||
package org.example.optional; |
|||
|
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* 地址 |
|||
* |
|||
* @author Admin |
|||
* @date 2022/12/22 |
|||
*/ |
|||
|
|||
@Data |
|||
public class Address { |
|||
private String city; |
|||
private String province; |
|||
} |
@ -0,0 +1,78 @@ |
|||
package org.example.optional; |
|||
|
|||
|
|||
import java.util.Optional; |
|||
|
|||
/** |
|||
* 可选测试 |
|||
* Optional |
|||
* @author xiaomage |
|||
* @date 2022/12/22 |
|||
*/ |
|||
public class OptionalTest { |
|||
|
|||
public static void main(String[] args) throws Exception { |
|||
|
|||
Student student = new Student("haha"); |
|||
student = null; |
|||
|
|||
if (student != null) { |
|||
String name = student.getName(); |
|||
} |
|||
|
|||
//直接判空 不推荐使用 代码依旧冗余
|
|||
Optional<Student> studentB = Optional.ofNullable(student); |
|||
if (studentB.isPresent()) { |
|||
System.out.println(studentB.get().getName()); |
|||
} |
|||
|
|||
//正确的操作 用流式操作
|
|||
Optional.ofNullable(student).ifPresent(stu -> System.out.println(stu.getName())); |
|||
|
|||
|
|||
// if (student != null) {
|
|||
// if (student.getAddress() != null) {
|
|||
// Address address = student.getAddress();
|
|||
// if (address.getCity() != null) {
|
|||
// System.out.println(address.getCity());
|
|||
// }
|
|||
// }
|
|||
// }
|
|||
// throw new RuntimeException("有空值");
|
|||
|
|||
Optional.ofNullable(student) |
|||
.map(Student::getAddress) |
|||
.map(Address::getCity) |
|||
.orElseThrow(()->new Exception("有空值")); |
|||
|
|||
} |
|||
|
|||
public Student getStudent(Student student) throws RuntimeException { |
|||
if (student != null) { |
|||
String name = student.getName(); |
|||
if ("xiaomage".equals(name)) { |
|||
return student; |
|||
} |
|||
student = new Student(); |
|||
student.setName("xiaomage"); |
|||
return student; |
|||
} else { |
|||
student = new Student(); |
|||
student.setName("xiaomage"); |
|||
return student; |
|||
} |
|||
} |
|||
|
|||
|
|||
public Student getStudent2(Student student) { |
|||
return Optional.ofNullable(student) |
|||
.filter(stu -> "xiaomage".equals(stu.getName())) |
|||
.orElseGet(() -> { |
|||
Student studentNew = new Student(); |
|||
studentNew.setName("xiaomage"); |
|||
return studentNew; |
|||
}); |
|||
} |
|||
|
|||
|
|||
} |
@ -0,0 +1,25 @@ |
|||
package org.example.optional; |
|||
|
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* 学生 |
|||
* |
|||
* @author xiaomage |
|||
* @date 2022/12/22 |
|||
*/ |
|||
@Data |
|||
public class Student { |
|||
|
|||
public Student() { |
|||
} |
|||
|
|||
public Student(String name) { |
|||
this.name = name; |
|||
} |
|||
|
|||
private String name; |
|||
private Address address; |
|||
|
|||
} |
@ -0,0 +1,17 @@ |
|||
package org.example.zhuangshi; |
|||
|
|||
|
|||
/** |
|||
* @Author: xiaomage |
|||
* @Date: 2022-10-07 15:21 |
|||
* @Description: 时尚 网咖 |
|||
*/ |
|||
public class FadInternetCafe implements ISurfTheInternetService { |
|||
|
|||
@Override |
|||
public void doSurfing() { |
|||
|
|||
System.out.println("在时尚 网咖 ,网上冲浪咯~"); |
|||
|
|||
} |
|||
} |
@ -0,0 +1,14 @@ |
|||
package org.example.zhuangshi; |
|||
|
|||
/** |
|||
* @className: ISurfTheInternetService |
|||
* @author: xiaomage |
|||
* @date: 2022/12/21 |
|||
**/ |
|||
public interface ISurfTheInternetService { |
|||
|
|||
/** |
|||
* 冲起来 |
|||
*/ |
|||
void doSurfing(); |
|||
} |
@ -0,0 +1,25 @@ |
|||
package org.example.zhuangshi; |
|||
|
|||
|
|||
public class MainTest { |
|||
|
|||
public static void main(String[] args) { |
|||
ISurfTheInternetService retroInternetBarService = new RetroInternetBar(); |
|||
////
|
|||
//// fadInternetCafeService.doSurfing();
|
|||
//// retroInternetBarService.doSurfing();
|
|||
//
|
|||
//
|
|||
//
|
|||
//
|
|||
// SurfDecorator retroInternetBarDecoratorService = new SurfDecorator(retroInternetBarService);
|
|||
// retroInternetBarDecoratorService.doSurfing();
|
|||
|
|||
//先装一哈
|
|||
SurfDecorator retroInternetBarDecoratorService = new SurfDecorator(retroInternetBarService); |
|||
//再包装一哈
|
|||
RechargeDecorator rechargeDecorator = new RechargeDecorator(retroInternetBarDecoratorService); |
|||
rechargeDecorator.doSurfing(); |
|||
|
|||
} |
|||
} |
@ -0,0 +1,25 @@ |
|||
package org.example.zhuangshi; |
|||
|
|||
|
|||
|
|||
/** |
|||
* @Author: xiaomage |
|||
* @Date: 2022-10-07 15:29 |
|||
* @Description: |
|||
*/ |
|||
public class RechargeDecorator extends SurfDecorator{ |
|||
|
|||
public RechargeDecorator(ISurfTheInternetService surfTheInternetService) { |
|||
super(surfTheInternetService); |
|||
} |
|||
|
|||
@Override |
|||
public void doSurfing() { |
|||
super.doSurfing(); |
|||
checkRecharge(); |
|||
} |
|||
private void checkRecharge(){ |
|||
System.out.print("RechargeDecorator 也在增强,看看这个货卡里面充了有多少,就来上网"); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,14 @@ |
|||
package org.example.zhuangshi; |
|||
|
|||
/** |
|||
* @Author: xiaomage |
|||
* @Date: 2022-10-07 15:21 |
|||
* @Description: 复古 网吧 |
|||
*/ |
|||
public class RetroInternetBar implements ISurfTheInternetService { |
|||
|
|||
@Override |
|||
public void doSurfing() { |
|||
System.out.println("在复古 网吧 ,网上冲浪咯~"); |
|||
} |
|||
} |
@ -0,0 +1,35 @@ |
|||
package org.example.zhuangshi; |
|||
|
|||
/** |
|||
* @Author: JCccc |
|||
* @Date: 2022-10-07 15:29 |
|||
* @Description: |
|||
*/ |
|||
public class SurfDecorator implements ISurfTheInternetService { |
|||
|
|||
/** |
|||
* 内部维护一个冲浪接口类 |
|||
*/ |
|||
private ISurfTheInternetService surfTheInternetService; |
|||
|
|||
/** |
|||
* 构造方法 把传入的 类 赋值给内部类 |
|||
* |
|||
* @param surfTheInternetService |
|||
*/ |
|||
public SurfDecorator(ISurfTheInternetService surfTheInternetService) { |
|||
this.surfTheInternetService = surfTheInternetService; |
|||
} |
|||
|
|||
/** |
|||
* 增强的网上冲浪方法 |
|||
*/ |
|||
@Override |
|||
public void doSurfing() { |
|||
|
|||
System.out.println("SurfDecorator 模拟业务 增强器在玩一点很新的东西,可能是一些额外的职责业务...."); |
|||
surfTheInternetService.doSurfing(); |
|||
System.out.println("SurfDecorator 模拟业务 增强器在玩一点很新的东西,可能是一些额外的职责业务,比如说是XXXX"); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,24 @@ |
|||
package org.example.zhuangshinew; |
|||
|
|||
|
|||
/** |
|||
* 食物装饰类 |
|||
* |
|||
* @author xiaomage |
|||
* @date 2022/12/21 |
|||
*/ |
|||
public class FoodDecorator implements IwatchFilm { |
|||
|
|||
private IwatchFilm iwatchFilm; |
|||
|
|||
public FoodDecorator(IwatchFilm iwatchFilm) { |
|||
this.iwatchFilm = iwatchFilm; |
|||
} |
|||
|
|||
@Override |
|||
public void watch() { |
|||
System.out.println("我买了好多零食!"); |
|||
iwatchFilm.watch(); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,23 @@ |
|||
package org.example.zhuangshinew; |
|||
|
|||
|
|||
/** |
|||
* 女朋友装饰类 |
|||
* |
|||
* @author xiaomage |
|||
* @date 2022/12/21 |
|||
*/ |
|||
public class GirlFriendDecorator extends FoodDecorator { |
|||
|
|||
public GirlFriendDecorator(IwatchFilm iwatchFilm) { |
|||
super(iwatchFilm); |
|||
} |
|||
|
|||
@Override |
|||
public void watch() { |
|||
System.out.println("带着女朋友看电影"); |
|||
super.watch(); |
|||
} |
|||
|
|||
|
|||
} |
@ -0,0 +1,14 @@ |
|||
package org.example.zhuangshinew; |
|||
|
|||
|
|||
/** |
|||
* 业务类 |
|||
* @author xiaomage |
|||
* @date 2022/12/21 |
|||
*/ |
|||
public class HaoHuaFilm implements IwatchFilm { |
|||
@Override |
|||
public void watch() { |
|||
System.out.println("在豪华影院看电影"); |
|||
} |
|||
} |
@ -0,0 +1,10 @@ |
|||
package org.example.zhuangshinew; |
|||
|
|||
/** |
|||
* @className: IwatchFilm |
|||
* @author: xiaomage |
|||
* @date: 2022/12/21 |
|||
**/ |
|||
public interface IwatchFilm { |
|||
void watch(); |
|||
} |
@ -0,0 +1,22 @@ |
|||
package org.example.zhuangshinew; |
|||
|
|||
|
|||
public class MainTest { |
|||
public static void main(String[] args) { |
|||
|
|||
// IwatchFilm iwatchFilm = new HaoHuaFilm();
|
|||
// iwatchFilm.watch();
|
|||
|
|||
// IwatchFilm iwatchFilm = new HaoHuaFilm();
|
|||
//
|
|||
// IwatchFilm foodDecorator = new FoodDecorator(iwatchFilm) ;
|
|||
// foodDecorator.watch();
|
|||
|
|||
|
|||
IwatchFilm iwatchFilm = new HaoHuaFilm(); |
|||
IwatchFilm foodDecorator = new FoodDecorator(iwatchFilm) ; |
|||
IwatchFilm girlFriendDecorator = new GirlFriendDecorator(foodDecorator); |
|||
girlFriendDecorator.watch(); |
|||
|
|||
} |
|||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue