Skip to content

Commit e4ac8ce

Browse files
committed
修改stream使用规范
1 parent 69ffebb commit e4ac8ce

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

backend/code/java中stream使用规范.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# java中stream使用规范
22

3-
## 1. stream中的filter表达式不要写得太长,对于复杂的表达式建议封装方法;
3+
## stream使用规范
4+
5+
### 1. stream中的filter表达式不要写得太长,对于复杂的表达式建议封装方法
46

57
例如:
68

79
```java
810
List<FlightOrder> orders = orders.stream()
9-
.filter(order -> StringUtils.equals(order.status, "Submitted")
11+
.filter(order -> StringUtils.equals(order.status, "Submitted")
1012
&& StringUtils.equals(order.paymentStatus, "Billed")
1113
&& StringUtils.equals(order.authorizeStatus, "Passed"))
1214
.collect(Collectors.toList();
@@ -20,15 +22,15 @@ List<FlightOrder> orders = orders.stream()
2022
.collect(Collectors.toList();
2123
```
2224

23-
## 2. 不要嵌套使用stream,嵌套的steam可读性很差,建议将内层的stream封装成独立的方法;
25+
### 2. 不要嵌套使用stream,嵌套的steam可读性很差,建议将内层的stream封装成独立的方法
26+
27+
### 3. stream要适当地换行,不要写在一行中
2428

25-
## 3. stream要适当地换行,不要写在一行中;
29+
### 4. 不要在stream中访问数据库;
2630

27-
## 4. 不要在stream中访问数据库;
28-
2931
原因: 在循环中访问数据库往往导致性能问题。
3032

31-
## 5. 不要使用stream来更新数据,只用stream来查询
33+
### 5. 不要使用stream来更新数据,只用stream来查询
3234

3335
例如:
3436

0 commit comments

Comments
 (0)