1818import static zuo .biao .apijson .RequestMethod .GET ;
1919import static zuo .biao .apijson .RequestMethod .HEAD ;
2020import 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 ;
2323import static zuo .biao .apijson .RequestMethod .PUT ;
2424
2525import java .net .URLDecoder ;
5353import zuo .biao .apijson .server .exception .NotExistException ;
5454import 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 )
0 commit comments