File tree Expand file tree Collapse file tree 12 files changed +503
-14
lines changed Expand file tree Collapse file tree 12 files changed +503
-14
lines changed Original file line number Diff line number Diff line change
1
+ # Batch
2
+
3
+ ### 用 title 改变标题帮助识别当前运行的内容
Original file line number Diff line number Diff line change 14
14
``` sh
15
15
sed -in " s/\$ " {" key}/$key /g" pom.xml
16
16
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
17
27
```
Original file line number Diff line number Diff line change 1
1
# 查询
2
2
3
+ ### 不要在 on 里加非关联条件
4
+
3
5
### selectOne 必须命中唯一索引
4
6
5
7
根据墨菲定律,如果不限制总会有脏数据导致查出多条导致报错
Original file line number Diff line number Diff line change 1
1
# 更新
2
2
3
+ ### 切记 set 之间用逗号而不是 AND 分隔
4
+
3
5
### 更新与删除操作需在事务下进行,需根据返回的影响条数做回滚等处理
4
6
5
7
对影响条数的判断可以避免拼接条件组合问题等情况导致全表更新/删除
Original file line number Diff line number Diff line change 4
4
5
5
### 开始结束中相同的代码应该抽取或使用切面,以免忘记且减少重复
6
6
7
+ ### 使用函数式设计(无状态),慎用成员变量和线程上下文,避免造成线程污染
8
+
9
+ - 新手最容易写出的生产问题就是成员变量,或者误认为线程安全的静态变量,比如` SimpleDateFormat `
10
+ - 线程上下文的问题比如使用` PageHelper.startPage(1, 10) ` 后没有在` finally ` 中` clearPage() `
11
+
12
+
7
13
### 锁释放要放在 finally
8
14
9
15
- 独占锁:可重入锁 ` reentrantLock.unlock(); `
Original file line number Diff line number Diff line change
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 ` 的定义
Original file line number Diff line number Diff line change @@ -18,6 +18,13 @@ https://phauer.com/2020/package-by-feature/
18
18
### 使用` package-info.java ` 配合文档注释说明包的作用
19
19
20
20
21
+ ## 类
22
+
23
+ ### 少用嵌套类,不同文件更直观
24
+
25
+ ### 一个文件的代码行数一个屏幕(Google 王争)
26
+
27
+
21
28
## 方法
22
29
23
30
### 不应该在一个文件中有多个方法,除非方法之间没有依赖,或者由上到下依赖
@@ -56,7 +63,8 @@ if ... {
56
63
a = ...
57
64
} else if {
58
65
a = ...
59
- }
66
+ } else if {
67
+ ...
60
68
```
61
69
62
70
抽取成:
@@ -66,5 +74,10 @@ if (...) {
66
74
return ...
67
75
} else if {
68
76
return ...
69
- }
70
- ```
77
+ } else if {
78
+ ...
79
+ ```
80
+
81
+ while 预定义除外
82
+
83
+ ### switch 较多时抽取成方法,减少 break
Original file line number Diff line number Diff line change 10
10
11
11
### 返回集合的语句单独成行方便调试
12
12
13
- for 循环、addAll 等情况不用执行表达式就能看 size 和内容
13
+ for 循环、addAll 等情况在调试时不用执行表达式就能看 size 和内容
14
+
15
+ ### 除了流创建以外,每一步处理应单独成行
16
+
17
+ ### ? : && || 除非特别短,否则应单独成行,并且把符号放在新行代码前面
14
18
15
19
16
20
### 常量数组和枚举单独成行,最后一项也加逗号
Original file line number Diff line number Diff line change @@ -15,12 +15,12 @@ info 级别下的输出应该是比较干净的,可以降级的都降级,不
15
15
全文搜索每个级别的代码量
16
16
17
17
``` 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)\( [^;]*;
24
24
```
25
25
26
26
Original file line number Diff line number Diff line change @@ -77,10 +77,9 @@ javac 参数参考:https://docs.oracle.com/javase/8/docs/technotes/tools/windo
77
77
78
78
依赖问题:
79
79
```
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)
84
83
```
85
84
86
85
编译问题:
You can’t perform that action at this time.
0 commit comments