Skip to content

Commit b804c00

Browse files
committed
Server:POST_GET改为GETS,POST_HEAD改为HEADS
1 parent a611a28 commit b804c00

File tree

9 files changed

+97
-88
lines changed

9 files changed

+97
-88
lines changed

APIJSON-Java-Server/APIJSON-Eclipse/src/main/java/apijson/demo/server/Controller.java

Lines changed: 70 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
import static zuo.biao.apijson.RequestMethod.GET;
1919
import static zuo.biao.apijson.RequestMethod.HEAD;
2020
import static zuo.biao.apijson.RequestMethod.POST;
21-
import static zuo.biao.apijson.RequestMethod.POST_GET;
22-
import static zuo.biao.apijson.RequestMethod.POST_HEAD;
21+
import static zuo.biao.apijson.RequestMethod.GETS;
22+
import static zuo.biao.apijson.RequestMethod.HEADS;
2323
import static zuo.biao.apijson.RequestMethod.PUT;
2424

2525
import java.net.URLDecoder;
@@ -53,10 +53,11 @@
5353
import zuo.biao.apijson.server.exception.NotExistException;
5454
import zuo.biao.apijson.server.exception.OutOfRangeException;
5555

56-
/**request receiver and controller
57-
* <br > 如果用在金融等对安全要求很高的领域,get和head可以测试期间使用明文的HTTP GET,上线版改用非明文的HTTP POST,兼顾系统安全与开发效率。
58-
* <br > get,head等接口都用HTTP GET方法请求,post,put,delete等接口都用HTTP POST方法请求。
59-
* <br > 这样做是为了前端和客户端方便,只需要做GET和POST请求。也可以改用实际对应的方法。
56+
/**request controller
57+
* <br > 建议全通过HTTP POST来请求:
58+
* <br > 1.减少代码 - 客户端无需写HTTP GET,PUT等各种方式的请求代码
59+
* <br > 2.提高性能 - 无需URL encode和decode
60+
* <br > 3.调试方便 - 建议使用 APIJSON在线测试工具 或 Postman
6061
* @author Lemon
6162
*/
6263
@RestController
@@ -66,37 +67,6 @@ public class Controller {
6667

6768
//通用接口,非事务型操作 和 简单事务型操作 都可通过这些接口自动化实现<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
6869

69-
/**获取
70-
* @param request 只用String,避免encode后未decode
71-
* @param session
72-
* @return
73-
* @see {@link RequestMethod#GET}
74-
*/
75-
@RequestMapping("get/{request}")
76-
public String open_get(@PathVariable String request, HttpSession session) {
77-
try {
78-
request = URLDecoder.decode(request, StringUtil.UTF_8);
79-
} catch (Exception e) {
80-
// Parser会报错
81-
}
82-
return get(request, session);
83-
}
84-
85-
/**计数
86-
* @param request 只用String,避免encode后未decode
87-
* @param session
88-
* @return
89-
* @see {@link RequestMethod#HEAD}
90-
*/
91-
@RequestMapping("head/{request}")
92-
public String open_head(@PathVariable String request, HttpSession session) {
93-
try {
94-
request = URLDecoder.decode(request, StringUtil.UTF_8);
95-
} catch (Exception e) {
96-
// Parser会报错
97-
}
98-
return head(request, session);
99-
}
10070

10171
/**获取
10272
* @param request 只用String,避免encode后未decode
@@ -120,26 +90,26 @@ public String head(@RequestBody String request, HttpSession session) {
12090
return new Parser(HEAD).setSession(session).parse(request);
12191
}
12292

123-
/**用POST方法GET,request和response都非明文,浏览器看不到,用于对安全性要求高的GET请求
93+
/**限制性GET,request和response都非明文,浏览器看不到,用于对安全性要求高的GET请求
12494
* @param request 只用String,避免encode后未decode
12595
* @param session
12696
* @return
127-
* @see {@link RequestMethod#POST_GET}
97+
* @see {@link RequestMethod#GETS}
12898
*/
129-
@RequestMapping(value = "post_get", method = org.springframework.web.bind.annotation.RequestMethod.POST)
130-
public String post_get(@RequestBody String request, HttpSession session) {
131-
return new Parser(POST_GET).setSession(session).parse(request);
99+
@RequestMapping(value = "gets", method = org.springframework.web.bind.annotation.RequestMethod.POST)
100+
public String gets(@RequestBody String request, HttpSession session) {
101+
return new Parser(GETS).setSession(session).parse(request);
132102
}
133103

134-
/**用POST方法HEAD,request和response都非明文,浏览器看不到,用于对安全性要求高的HEAD请求
104+
/**限制性HEAD,request和response都非明文,浏览器看不到,用于对安全性要求高的HEAD请求
135105
* @param request 只用String,避免encode后未decode
136106
* @param session
137107
* @return
138-
* @see {@link RequestMethod#POST_HEAD}
108+
* @see {@link RequestMethod#HEADS}
139109
*/
140-
@RequestMapping(value = "post_head", method = org.springframework.web.bind.annotation.RequestMethod.POST)
141-
public String post_head(@RequestBody String request, HttpSession session) {
142-
return new Parser(POST_HEAD).setSession(session).parse(request);
110+
@RequestMapping(value = "heads", method = org.springframework.web.bind.annotation.RequestMethod.POST)
111+
public String heads(@RequestBody String request, HttpSession session) {
112+
return new Parser(HEADS).setSession(session).parse(request);
143113
}
144114

145115
/**新增
@@ -175,6 +145,45 @@ public String delete(@RequestBody String request, HttpSession session) {
175145
return new Parser(DELETE).setSession(session).parse(request);
176146
}
177147

148+
149+
150+
151+
152+
/**获取
153+
* 只为兼容HTTP GET请求,推荐用HTTP POST,可删除
154+
* @param request 只用String,避免encode后未decode
155+
* @param session
156+
* @return
157+
* @see {@link RequestMethod#GET}
158+
*/
159+
@RequestMapping("get/{request}")
160+
public String open_get(@PathVariable String request, HttpSession session) {
161+
try {
162+
request = URLDecoder.decode(request, StringUtil.UTF_8);
163+
} catch (Exception e) {
164+
// Parser会报错
165+
}
166+
return get(request, session);
167+
}
168+
169+
/**计数
170+
* 只为兼容HTTP GET请求,推荐用HTTP POST,可删除
171+
* @param request 只用String,避免encode后未decode
172+
* @param session
173+
* @return
174+
* @see {@link RequestMethod#HEAD}
175+
*/
176+
@RequestMapping("head/{request}")
177+
public String open_head(@PathVariable String request, HttpSession session) {
178+
try {
179+
request = URLDecoder.decode(request, StringUtil.UTF_8);
180+
} catch (Exception e) {
181+
// Parser会报错
182+
}
183+
return head(request, session);
184+
}
185+
186+
178187
//通用接口,非事务型操作 和 简单事务型操作 都可通过这些接口自动化实现>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
179188

180189

@@ -293,30 +302,30 @@ public JSONObject postVerify(@RequestBody String request) {
293302
* @param request
294303
* @return
295304
*/
296-
@RequestMapping(value = "post_get/verify", method = org.springframework.web.bind.annotation.RequestMethod.POST)
305+
@RequestMapping(value = "gets/verify", method = org.springframework.web.bind.annotation.RequestMethod.POST)
297306
public JSONObject getVerify(@RequestBody String request) {
298307
JSONObject requestObject = null;
299308
String phone;
300309
try {
301-
requestObject = Parser.parseRequest(request, POST_GET);
310+
requestObject = Parser.parseRequest(request, GETS);
302311
phone = requestObject.getString(PHONE);
303312
} catch (Exception e) {
304313
return Parser.extendErrorResult(requestObject, e);
305314
}
306-
return new Parser(POST_GET, true).parseResponse(newVerifyRequest(phone, null));
315+
return new Parser(GETS, true).parseResponse(newVerifyRequest(phone, null));
307316
}
308317

309318
/**校验验证码
310319
* @param request
311320
* @return
312321
*/
313-
@RequestMapping(value = "post_head/verify", method = org.springframework.web.bind.annotation.RequestMethod.POST)
322+
@RequestMapping(value = "heads/verify", method = org.springframework.web.bind.annotation.RequestMethod.POST)
314323
public JSONObject headVerify(@RequestBody String request) {
315324
JSONObject requestObject = null;
316325
String phone;
317326
String verify;
318327
try {
319-
requestObject = Parser.parseRequest(request, POST_HEAD);
328+
requestObject = Parser.parseRequest(request, HEADS);
320329
phone = requestObject.getString(PHONE);
321330
verify = requestObject.getString(VERIFY);
322331
} catch (Exception e) {
@@ -332,7 +341,7 @@ public JSONObject headVerify(@RequestBody String request) {
332341
*/
333342
public JSONObject headVerify(String phone, String vfy) {
334343
JSONResponse response = new JSONResponse(
335-
new Parser(POST_GET, true).parseResponse(
344+
new Parser(GETS, true).parseResponse(
336345
new JSONRequest(new Verify(phone)).setTag(VERIFY_)
337346
)
338347
);
@@ -350,7 +359,7 @@ public JSONObject headVerify(String phone, String vfy) {
350359
}
351360

352361
return new JSONResponse(
353-
new Parser(POST_HEAD, true).parseResponse(
362+
new Parser(HEADS, true).parseResponse(
354363
new JSONRequest(new Verify(phone, vfy))
355364
)
356365
);
@@ -413,7 +422,7 @@ public JSONObject login(@RequestBody String request, HttpSession session) {
413422

414423

415424
//手机号是否已注册
416-
JSONObject phoneResponse = new Parser(POST_HEAD, true).parseResponse(
425+
JSONObject phoneResponse = new Parser(HEADS, true).parseResponse(
417426
new JSONRequest(
418427
new Privacy().setPhone(phone)
419428
)
@@ -427,7 +436,7 @@ public JSONObject login(@RequestBody String request, HttpSession session) {
427436
}
428437

429438
//根据phone获取User
430-
JSONObject privacyResponse = new Parser(POST_GET, true).parseResponse(
439+
JSONObject privacyResponse = new Parser(GETS, true).parseResponse(
431440
new JSONRequest(
432441
new Privacy().setPhone(phone)
433442
)
@@ -443,7 +452,7 @@ public JSONObject login(@RequestBody String request, HttpSession session) {
443452
//校验凭证
444453
if (isPassword) {//password密码登录
445454
response = new JSONResponse(
446-
new Parser(POST_HEAD, true).parseResponse(
455+
new Parser(HEADS, true).parseResponse(
447456
new JSONRequest(new Privacy(userId).setPassword(password))
448457
)
449458
);
@@ -459,7 +468,7 @@ public JSONObject login(@RequestBody String request, HttpSession session) {
459468
}
460469

461470
response = new JSONResponse(
462-
new Parser(POST_GET, true).parseResponse(
471+
new Parser(GETS, true).parseResponse(
463472
new JSONRequest(new User(userId))
464473
)
465474
);
@@ -582,7 +591,7 @@ public JSONObject register(@RequestBody String request) {
582591
}
583592

584593
//验证手机号是否已经注册
585-
JSONObject check = new Parser(POST_HEAD, true).parseResponse(
594+
JSONObject check = new Parser(HEADS, true).parseResponse(
586595
new JSONRequest(
587596
new Privacy().setPhone(phone)
588597
)
@@ -762,7 +771,7 @@ public JSONObject putBalance(@RequestBody String request, HttpSession session) {
762771

763772
privacyObj.remove("balance+");
764773
JSONResponse response = new JSONResponse(
765-
new Parser(POST_HEAD, true).setSession(session).parseResponse(
774+
new Parser(HEADS, true).setSession(session).parseResponse(
766775
new JSONRequest(PRIVACY_, privacyObj)
767776
)
768777
);
@@ -787,7 +796,7 @@ public JSONObject putBalance(@RequestBody String request, HttpSession session) {
787796

788797
if (change < 0) {//提现
789798
response = new JSONResponse(
790-
new Parser(POST_GET, true).parseResponse(
799+
new Parser(GETS, true).parseResponse(
791800
new JSONRequest(
792801
new Privacy(userId)
793802
)

APIJSON-Java-Server/APIJSON-Eclipse/src/main/java/apijson/demo/server/Verifier.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
import static zuo.biao.apijson.RequestMethod.GET;
1919
import static zuo.biao.apijson.RequestMethod.HEAD;
2020
import static zuo.biao.apijson.RequestMethod.POST;
21-
import static zuo.biao.apijson.RequestMethod.POST_GET;
22-
import static zuo.biao.apijson.RequestMethod.POST_HEAD;
21+
import static zuo.biao.apijson.RequestMethod.GETS;
22+
import static zuo.biao.apijson.RequestMethod.HEADS;
2323
import static zuo.biao.apijson.RequestMethod.PUT;
2424

2525
import java.util.ArrayList;
@@ -96,8 +96,8 @@ private static HashMap<RequestMethod, RequestRole[]> getAccessMap(MethodAccess a
9696
HashMap<RequestMethod, RequestRole[]> map = new HashMap<>();
9797
map.put(GET, access.GET());
9898
map.put(HEAD, access.HEAD());
99-
map.put(POST_GET, access.POST_GET());
100-
map.put(POST_HEAD, access.POST_HEAD());
99+
map.put(GETS, access.GETS());
100+
map.put(HEADS, access.HEADS());
101101
map.put(POST, access.POST());
102102
map.put(PUT, access.PUT());
103103
map.put(DELETE, access.DELETE());

APIJSON-Java-Server/APIJSON-Eclipse/src/main/java/apijson/demo/server/model/Privacy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626
@MethodAccess(
2727
GET = {},
28-
POST_GET = {OWNER, ADMIN},
28+
GETS = {OWNER, ADMIN},
2929
POST = {UNKNOWN, ADMIN},
3030
DELETE = {ADMIN}
3131
)

APIJSON-Java-Server/APIJSON-Eclipse/src/main/java/apijson/demo/server/model/Verify.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
@MethodAccess(
3131
GET = {},
3232
HEAD = {},
33-
POST_GET = {UNKNOWN, LOGIN, CONTACT, CIRCLE, OWNER, ADMIN},
34-
POST_HEAD = {UNKNOWN, LOGIN, CONTACT, CIRCLE, OWNER, ADMIN},
33+
GETS = {UNKNOWN, LOGIN, CONTACT, CIRCLE, OWNER, ADMIN},
34+
HEADS = {UNKNOWN, LOGIN, CONTACT, CIRCLE, OWNER, ADMIN},
3535
POST = {UNKNOWN, LOGIN, CONTACT, CIRCLE, OWNER, ADMIN},
3636
PUT = {ADMIN},
3737
DELETE = {ADMIN}

APIJSON-Java-Server/APIJSON-Eclipse/src/main/java/zuo/biao/apijson/MethodAccess.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@
4545
*/
4646
RequestRole[] HEAD() default {UNKNOWN, LOGIN, CONTACT, CIRCLE, OWNER, ADMIN};
4747

48-
/**@see {@link RequestMethod#POST_GET}
48+
/**@see {@link RequestMethod#GETS}
4949
* @return 该请求方法允许的角色 default {LOGIN, CONTACT, CIRCLE, OWNER, ADMIN};
5050
*/
51-
RequestRole[] POST_GET() default {LOGIN, CONTACT, CIRCLE, OWNER, ADMIN};
51+
RequestRole[] GETS() default {LOGIN, CONTACT, CIRCLE, OWNER, ADMIN};
5252

53-
/**@see {@link RequestMethod#POST_HEAD}
53+
/**@see {@link RequestMethod#HEADS}
5454
* @return 该请求方法允许的角色 default {LOGIN, CONTACT, CIRCLE, OWNER, ADMIN};
5555
*/
56-
RequestRole[] POST_HEAD() default {LOGIN, CONTACT, CIRCLE, OWNER, ADMIN};
56+
RequestRole[] HEADS() default {LOGIN, CONTACT, CIRCLE, OWNER, ADMIN};
5757

5858
/**@see {@link RequestMethod#POST}
5959
* @return 该请求方法允许的角色 default {LOGIN, ADMIN};

APIJSON-Java-Server/APIJSON-Eclipse/src/main/java/zuo/biao/apijson/MethodStructure.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@
3030
@Target(TYPE)
3131
public @interface MethodStructure {
3232

33-
/**@see {@link RequestMethod#POST_HEAD}
33+
/**@see {@link RequestMethod#HEADS}
3434
* @return 该请求方法允许的结构
3535
*/
36-
String POST_HEAD() default "";
36+
String HEADS() default "";
3737

38-
/**@see {@link RequestMethod#POST_GET}
38+
/**@see {@link RequestMethod#GETS}
3939
* @return 该请求方法允许的结构
4040
*/
41-
String POST_GET() default "";
41+
String GETS() default "";
4242

4343
/**@see {@link RequestMethod#POST}
4444
* @return 该请求方法允许的结构

APIJSON-Java-Server/APIJSON-Eclipse/src/main/java/zuo/biao/apijson/RequestMethod.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
package zuo.biao.apijson;
1616

17-
/**请求方法,对应org.springframework.web.bind.annotation.RequestMethod,多出POST_GET,POST_HEAD方法
17+
/**请求方法,对应org.springframework.web.bind.annotation.RequestMethod,多出GETS,HEADS方法
1818
* @author Lemon
1919
*/
2020
public enum RequestMethod {
@@ -29,15 +29,15 @@ public enum RequestMethod {
2929
*/
3030
HEAD,
3131

32-
/**TODO 改为GETS
33-
* 通过POST来GET数据,不显示请求内容和返回结果,并且校验请求,一般用于对安全要求比较高的请求
32+
/**Safe, Single, Simple
33+
* <br > 限制性GET,通过POST来GET数据,不显示请求内容和返回结果,并且校验请求,一般用于对安全要求比较高的请求
3434
*/
35-
POST_GET,
35+
GETS,
3636

37-
/**TODO 改为HEADS
38-
* 通过POST来HEAD数据,不显示请求内容和返回结果,并且校验请求,一般用于对安全要求比较高的请求
37+
/**Safe, Single, Simple
38+
* <br > 限制性HEAD,通过POST来HEAD数据,不显示请求内容和返回结果,并且校验请求,一般用于对安全要求比较高的请求
3939
*/
40-
POST_HEAD,
40+
HEADS,
4141

4242
/**
4343
* 新增(或者说插入)数据
@@ -62,7 +62,7 @@ public enum RequestMethod {
6262
*/
6363
public static boolean isGetMethod(RequestMethod method, boolean containPrivate) {
6464
boolean is = method == null || method == GET;
65-
return containPrivate == false ? is : is || method == POST_GET;
65+
return containPrivate == false ? is : is || method == GETS;
6666
}
6767

6868
/**是否为HEAD请求方法
@@ -72,7 +72,7 @@ public static boolean isGetMethod(RequestMethod method, boolean containPrivate)
7272
*/
7373
public static boolean isHeadMethod(RequestMethod method, boolean containPrivate) {
7474
boolean is = method == HEAD;
75-
return containPrivate == false ? is : is || method == POST_HEAD;
75+
return containPrivate == false ? is : is || method == HEADS;
7676
}
7777

7878
/**是否为查询的请求方法

0 commit comments

Comments
 (0)