forked from hellokaton/write-readable-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample1.java
More file actions
57 lines (49 loc) · 1.26 KB
/
Copy pathExample1.java
File metadata and controls
57 lines (49 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package chapter_13;
/**
* 清楚的描述逻辑
*
* @author biezhi
* @date 2018/9/1
*/
public class Example1 {
private boolean isAdminRequest(){
return false;
}
private String noAuthorized(){
return "authorized.html";
}
class Session {
public String getAttribute(String key) {
return "";
}
}
class Document {
String username;
}
// public String part1(Document document, Session session){
// boolean isAdmin = isAdminRequest();
// if(null != document){
// if(!isAdmin && document.username != session.getAttribute("username")){
// return noAuthorized();
// }
// } else {
// if(!isAdmin) {
// return noAuthorized();
// }
// }
// // 渲染正常页面
// return "biezhi.html";
// }
public String part2(Document document, Session session){
boolean isAdmin = isAdminRequest();
if(isAdmin){
// 获取信息
} else if(document.username.equals(session.getAttribute("username"))){
// 获取信息
} else {
return noAuthorized();
}
// 渲染正常页面
return "biezhi.html";
}
}