Skip to content

Commit 8e93841

Browse files
committed
正则笔记迁入和代码风格等
1 parent 57be03f commit 8e93841

File tree

12 files changed

+503
-14
lines changed

12 files changed

+503
-14
lines changed

DevOps/batch.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Batch
2+
3+
### 用 title 改变标题帮助识别当前运行的内容

DevOps/linux/sh_mnemonic.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,14 @@
1414
```sh
1515
sed -in "s/\$"{"key}/$key/g" pom.xml
1616
grep "行标识字符" pom.xml
17+
```
18+
19+
## 文件列表
20+
21+
```
22+
# Linux
23+
find -name *.java
24+
25+
# Windows 傻逼 fin(d)str
26+
dir /s/b finstr *.java
1727
```

db/curd/DB_select.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# 查询
22

3+
### 不要在 on 里加非关联条件
4+
35
### selectOne 必须命中唯一索引
46

57
根据墨菲定律,如果不限制总会有脏数据导致查出多条导致报错

db/curd/DB_update.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# 更新
22

3+
### 切记 set 之间用逗号而不是 AND 分隔
4+
35
### 更新与删除操作需在事务下进行,需根据返回的影响条数做回滚等处理
46

57
对影响条数的判断可以避免拼接条件组合问题等情况导致全表更新/删除

java/Java_Concurrent.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
### 开始结束中相同的代码应该抽取或使用切面,以免忘记且减少重复
66

7+
### 使用函数式设计(无状态),慎用成员变量和线程上下文,避免造成线程污染
8+
9+
- 新手最容易写出的生产问题就是成员变量,或者误认为线程安全的静态变量,比如`SimpleDateFormat`
10+
- 线程上下文的问题比如使用`PageHelper.startPage(1, 10)`后没有在`finally``clearPage()`
11+
12+
713
### 锁释放要放在 finally
814

915
- 独占锁:可重入锁 `reentrantLock.unlock();`

java/Java_reflection.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Java 反射
2+
3+
### 类的分类和类型
4+
5+
`Class.getEnclosingClass()`方法可以看到类分为 5 种
6+
- 顶级 Top level classes
7+
- 嵌套 Nested classes (static member classes)
8+
- 内部 Inner classes (non-static member classes)
9+
- 本地 Local classes (named classes declared within a method)
10+
- 匿名 Anonymous classes
11+
12+
`Type`的子类/接口可以看到类类型也分 5 种
13+
- Class(子类,其他都是接口)
14+
- GenericArrayType []/...
15+
- ParameterizedType <>
16+
- TypeVariable T
17+
- WildcardType ?
18+
19+
20+
### 显示类名可能是数组时用`getTypeName`(Exception不会是数组)
21+
22+
关于`className`的方法有四个
23+
- getSimpleName 匿名时空串
24+
- getName 数组时`[L类名;`
25+
- getTypeName 内部/匿名时`$`
26+
- getCanonicalName 内部/匿名时`null`
27+
28+
- Class.forName 用的是 getName 获得的
29+
- 原生类型不能用 forName
30+
- 原生类型数组大多数是用首字母如`int[].class`就是`[I`,注意末尾没分号
31+
- `boolean[].class``[Z``long`类型是`[J`
32+
33+
### 方法调用类型
34+
35+
下面的`~``invoke`的简写
36+
- S ~static 静态
37+
- O ~special 私有/构造/super
38+
- M ~virtual 实例(可重写)
39+
- I ~interface 实现(应重写)
40+
- D ~dynamic lambda
41+
main 方法可以继承运行,不算重写(不能`@Override`
42+
43+
### 使用 JDK 自带的类来做解析工具的接口返回
44+
45+
一些常量或类型可以用诸如`Modifier``ElementType`的定义

java/Java_structure.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ https://phauer.com/2020/package-by-feature/
1818
### 使用`package-info.java`配合文档注释说明包的作用
1919

2020

21+
##
22+
23+
### 少用嵌套类,不同文件更直观
24+
25+
### 一个文件的代码行数一个屏幕(Google 王争)
26+
27+
2128
## 方法
2229

2330
### 不应该在一个文件中有多个方法,除非方法之间没有依赖,或者由上到下依赖
@@ -56,7 +63,8 @@ if ... {
5663
a = ...
5764
} else if {
5865
a = ...
59-
}
66+
} else if {
67+
...
6068
```
6169

6270
抽取成:
@@ -66,5 +74,10 @@ if (...) {
6674
return ...
6775
} else if {
6876
return ...
69-
}
70-
```
77+
} else if {
78+
...
79+
```
80+
81+
while 预定义除外
82+
83+
### switch 较多时抽取成方法,减少 break

java/Java_style.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010

1111
### 返回集合的语句单独成行方便调试
1212

13-
for 循环、addAll 等情况不用执行表达式就能看 size 和内容
13+
for 循环、addAll 等情况在调试时不用执行表达式就能看 size 和内容
14+
15+
### 除了流创建以外,每一步处理应单独成行
16+
17+
### ? : && || 除非特别短,否则应单独成行,并且把符号放在新行代码前面
1418

1519

1620
### 常量数组和枚举单独成行,最后一项也加逗号

log/Java_log.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ info 级别下的输出应该是比较干净的,可以降级的都降级,不
1515
全文搜索每个级别的代码量
1616

1717
```regexp
18-
\.(trace|debug|info|warn|error)[^;]*;
19-
\.(trace)[^;]*;
20-
\.(debug)[^;]*;
21-
\.(info)[^;]*;
22-
\.(warn)[^;]*;
23-
\.(error)[^;]*;
18+
\.(trace|debug|info|warn|error)\([^;]*;
19+
\.(trace)\([^;]*;
20+
\.(debug)\([^;]*;
21+
\.(info)\([^;]*;
22+
\.(warn)\([^;]*;
23+
\.(error)\([^;]*;
2424
```
2525

2626

maven/Maven_dep.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,9 @@ javac 参数参考:https://docs.oracle.com/javase/8/docs/technotes/tools/windo
7777

7878
依赖问题:
7979
```
80-
Could not resolve dependencies for project 不能解析的依赖模块gav:
81-
The following artifacts could not be resolved:
82-
不能解析的模块gav1, 不能解析的模块gav2:
83-
Could not find artifact 找不到的包gav in 远程仓库ID (远程仓库URL)
80+
Could not resolve dependencies for project 出现问题的模块:
81+
The following artifacts could not be resolved: 不能解析的依赖列表:
82+
Could not find artifact 【找不到的包】 in 远程仓库ID (远程仓库URL)
8483
```
8584

8685
编译问题:

0 commit comments

Comments
 (0)