Skip to content

Commit 05af3af

Browse files
committed
refactor: refactor command pattern implementation in text editor
1 parent bf6e11a commit 05af3af

File tree

123 files changed

+1112
-1043
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+1112
-1043
lines changed
Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,42 @@
11
package com.helltractor.demo;
22

33
import org.aspectj.lang.ProceedingJoinPoint;
4-
import org.aspectj.lang.annotation.*;
4+
import org.aspectj.lang.annotation.After;
5+
import org.aspectj.lang.annotation.AfterReturning;
6+
import org.aspectj.lang.annotation.Around;
7+
import org.aspectj.lang.annotation.Aspect;
8+
import org.aspectj.lang.annotation.Before;
9+
import org.aspectj.lang.annotation.Pointcut;
510
import org.springframework.stereotype.Component;
611

712
/**
8-
* 切面类
9-
* 修改切点周围信息
13+
* 切面类,修改切点周围信息
1014
*/
11-
1215
@Aspect
1316
@Component
1417
public class AutoFillAspectJ {
15-
18+
1619
@Pointcut("execution(* com.helltractor.demo.service.IBuy.buy(..))")
1720
public void aopPointCut() {
18-
21+
1922
}
20-
23+
2124
@Before("aopPointCut()")
2225
// @Before("execution(* org.aopdemo.service.IBuy.buy(..)) && within(org.aopdemo.entity.*) && bean(girl)")
2326
public void haha() {
2427
System.out.println("男孩女孩都买了自己喜欢的东西");
2528
}
26-
29+
2730
@After("aopPointCut()")
2831
public void hehe() {
2932
System.out.println("After ...");
3033
}
31-
34+
3235
@AfterReturning("aopPointCut()")
3336
public void xixi() {
3437
System.out.println("AfterReturning ...");
3538
}
36-
39+
3740
@Around("aopPointCut()")
3841
public void xxx(ProceedingJoinPoint pj) {
3942
try {
@@ -44,13 +47,14 @@ public void xxx(ProceedingJoinPoint pj) {
4447
throwable.printStackTrace();
4548
}
4649
}
47-
50+
4851
@Pointcut("execution(* com.helltractor.demo.service.IBuy.buyPrice(double)) && args(price) && bean(girl)")
4952
public void gift(double price) {
5053
}
51-
54+
5255
/**
5356
* around notice
57+
*
5458
* @param pj, price
5559
*/
5660
// @Around("gift(price)")
@@ -68,5 +72,4 @@ public void gift(double price) {
6872
// }
6973
// return "衣服";
7074
// }
71-
72-
}
75+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
package com.helltractor.demo.annotation;
22

3-
import com.helltractor.demo.enumeration.OperationType;
4-
53
import java.lang.annotation.ElementType;
64
import java.lang.annotation.Retention;
75
import java.lang.annotation.RetentionPolicy;
86
import java.lang.annotation.Target;
97

8+
import com.helltractor.demo.enumeration.OperationType;
9+
1010
/**
11-
* 注解类
12-
* 实现切面自动填充
11+
* 注解类,实现切面自动填充
1312
*/
1413
@Target(ElementType.METHOD)
1514
@Retention(RetentionPolicy.RUNTIME)
1615
public @interface AutoFill {
16+
1717
OperationType value() default OperationType.INSERT;
1818
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
package com.helltractor.demo.entity;
22

3-
import com.helltractor.demo.service.IBuy;
43
import org.springframework.stereotype.Component;
54

5+
import com.helltractor.demo.service.IBuy;
6+
67
/**
7-
* 实现类
8-
* 实现接口
8+
* 实现类,实现接口
99
*/
10-
1110
@Component
1211
public class Boy implements IBuy {
12+
1313
@Override
1414
public String buy() {
1515
System.out.println("男孩买了一个游戏机");
1616
return "游戏机";
1717
}
18-
18+
1919
@Override
2020
public String buyPrice(double price) {
2121
System.out.println(String.format("男孩花了%s元买了一个游戏机", price));
2222
return "游戏机";
2323
}
24-
}
24+
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
package com.helltractor.demo.entity;
22

3-
import com.helltractor.demo.service.IBuy;
43
import org.springframework.stereotype.Component;
54

5+
import com.helltractor.demo.service.IBuy;
6+
67
/**
7-
* 实现类
8-
* 实现接口
8+
* 实现类,实现接口
99
*/
10-
1110
@Component
1211
public class Girl implements IBuy {
12+
1313
@Override
1414
public String buy() {
1515
System.out.println("女孩买了一件漂亮的衣服");
1616
return "衣服";
1717
}
18-
18+
1919
@Override
2020
public final String buyPrice(double price) {
2121
System.out.printf("女孩花了%s元买了一件漂亮的衣服%n", price);
2222
return "衣服";
2323
}
24-
25-
}
24+
25+
}
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
package com.helltractor.demo.enumeration;
22

33
/**
4-
* @Author: helltractor
5-
* @Date: 2024/3/30 14:51
6-
*/
7-
8-
/**
9-
* 枚举类
10-
* 枚举数据库操作方法
4+
* 枚举类,枚举数据库操作方法
115
*/
126
public enum OperationType {
137
INSERT,
14-
158
UPDATE,
169
}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package com.helltractor.demo.service;
22

33
/**
4-
* 服务类
5-
* 购买方法
4+
* 服务类,购买方法
65
*/
7-
86
public interface IBuy {
7+
98
String buy();
10-
9+
1110
String buyPrice(double price);
1211
}
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
11
package com.helltractor.demo;
22

3-
import com.helltractor.demo.config.AutoFillConfig;
4-
import com.helltractor.demo.entity.Boy;
5-
import com.helltractor.demo.entity.Girl;
63
import org.junit.jupiter.api.Test;
74
import org.springframework.boot.test.context.SpringBootTest;
85
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
96
import org.springframework.test.context.ContextConfiguration;
107

8+
import com.helltractor.demo.config.AutoFillConfig;
9+
import com.helltractor.demo.entity.Boy;
10+
import com.helltractor.demo.entity.Girl;
11+
1112
/**
1213
* 测试类
1314
*/
1415
@SpringBootTest
1516
@ContextConfiguration(classes = {AutoFillConfig.class})
1617
public class AutoFillTest {
18+
1719
@Test
1820
public void autoFillTest() {
1921
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AutoFillConfig.class);
2022
Boy boy = context.getBean("boy", Boy.class);
2123
Girl girl = (Girl) context.getBean("girl");
22-
24+
2325
boy.buy();
2426
girl.buy();
25-
27+
2628
String boyBought = boy.buyPrice(35);
2729
String girlBought = girl.buyPrice(99.8);
28-
30+
2931
System.out.println("男孩买到了:" + boyBought);
3032
System.out.println("女孩买到了:" + girlBought);
3133
}
32-
33-
}
34+
35+
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
package com.helltractor.demo.config;
22

3-
import com.helltractor.demo.AutoFillTest;
4-
import com.helltractor.demo.service.IBuy;
53
import org.springframework.context.annotation.ComponentScan;
64
import org.springframework.context.annotation.Configuration;
75
import org.springframework.context.annotation.EnableAspectJAutoProxy;
86

7+
import com.helltractor.demo.AutoFillTest;
8+
import com.helltractor.demo.service.IBuy;
9+
910
/**
10-
* 配置类
11-
* 配置 Spring Bean 扫描的基础路径和代理方式
11+
* 配置类,配置 Spring Bean 扫描的基础路径和代理方式
1212
*/
13-
1413
@Configuration
1514

1615
// 配置扫描的基础路径
@@ -19,4 +18,4 @@
1918
// 配置代理方式
2019
@EnableAspectJAutoProxy(proxyTargetClass = true)
2120
public class AutoFillConfig {
22-
}
21+
}

demo-consul/src/main/java/com/helltractor/demo/ConsulApplication.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
@SpringBootApplication
99
@RestController
1010
public class ConsulApplication {
11-
11+
1212
public static void main(String[] args) {
1313
SpringApplication.run(ConsulApplication.class, args);
1414
}
15-
15+
1616
@GetMapping("/")
1717
public String home() {
1818
return "Hello World!";
1919
}
20-
21-
}
20+
21+
}

demo-consul/src/main/resources/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ spring:
99
discovery:
1010
register: true
1111
hostname: localhost
12-
port: 8500
12+
port: 8500

0 commit comments

Comments
 (0)