Skip to content

Commit 6870389

Browse files
committed
新增post_get方法;同步idea版至eclipse版
1 parent 293a8e6 commit 6870389

File tree

5 files changed

+47
-40
lines changed

5 files changed

+47
-40
lines changed

APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/server/Controller.java

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
import org.springframework.web.bind.annotation.RequestMethod;
2121
import org.springframework.web.bind.annotation.RestController;
2222

23-
import com.alibaba.fastjson.JSONObject;
24-
25-
import zuo.biao.apijson.JSON;
26-
2723
/**request receiver and controller
2824
* @author Lemon
2925
*/
@@ -33,41 +29,34 @@ public class Controller {
3329

3430
@RequestMapping("get/{request}")
3531
public String get(@PathVariable String request) {
36-
System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n get/request = \n" + request);
37-
String response = JSON.toJSONString(new RequestParser(RequestMethod.GET).parse(request));
38-
System.out.println("get/request = \n" + request + "\n return response = \n" + response
39-
+ "\n >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
40-
return response;
32+
return new RequestParser(RequestMethod.GET).parse(request);
4133
}
4234

4335
@RequestMapping(value="post", method = RequestMethod.POST)
4436
public String post(@RequestBody String request) {
45-
System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n post/request = \n" + request);
46-
String response = JSON.toJSONString(new RequestParser(RequestMethod.POST).parse(request));
47-
System.out.println("post/request = \n" + request + "\n return response = \n" + response
48-
+ "\n >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
49-
return response;
37+
return new RequestParser(RequestMethod.POST).parse(request);
38+
}
39+
40+
/**用POST方法GET数据,request和response都非明文,浏览器看不到,用于对安全性要求高的GET请求
41+
* @param request
42+
* @return
43+
*/
44+
@RequestMapping(value="post_get", method = RequestMethod.POST)
45+
public String post_get(@RequestBody String request) {
46+
return new RequestParser(RequestMethod.GET).parse(request);
5047
}
5148

5249
/**以下接口继续用POST接口是为了客户端方便,只需要做get,post请求。也可以改用实际对应的方法。
5350
* post,put方法名可以改为add,update等更客户端容易懂的名称
5451
*/
5552
@RequestMapping(value="delete", method = RequestMethod.POST)
5653
public String delete(@RequestBody String request) {
57-
System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n delete/request = \n" + request);
58-
String response = JSON.toJSONString(new RequestParser(RequestMethod.DELETE).parse(request));
59-
System.out.println("delete/request = \n" + request + "\n return response = \n" + response
60-
+ "\n >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
61-
return response;
54+
return new RequestParser(RequestMethod.DELETE).parse(request);
6255
}
6356

6457
@RequestMapping(value="put", method = RequestMethod.POST)
6558
public String put(@RequestBody String request) {
66-
System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n put/request = \n" + request);
67-
String response = JSON.toJSONString(new RequestParser(RequestMethod.PUT).parse(request));
68-
System.out.println("put/request = \n" + request + "\n return response = \n" + response
69-
+ "\n >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
70-
return response;
59+
return new RequestParser(RequestMethod.PUT).parse(request);
7160
}
7261

7362
}

APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/server/QueryConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public static synchronized QueryConfig getQueryConfig(RequestMethod method, Stri
259259
config.setColumns(StringUtil.getString(set.toArray(new String[]{})));
260260
String valuesString = "";
261261
Collection<Object> valueCollection = request.values();
262-
Object[] values = valueCollection == null || valueCollection.isEmpty() ? null : valueCollection.toArray(new String[]{});
262+
Object[] values = valueCollection == null || valueCollection.isEmpty() ? null : valueCollection.toArray();
263263
if (values != null) {
264264
for (int i = 0; i < values.length; i++) {
265265
valuesString += ((i > 0 ? "," : "") + "'" + values[i] + "'");

APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/server/RequestParser.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,35 @@ public RequestParser(RequestMethod requestMethod) {
5757
private Map<String, String> relationMap;
5858

5959
/**解析请求json并获取对应结果
60-
* @param json
60+
* @param request
61+
* @return
62+
*/
63+
public String parse(String request) {
64+
String response = JSON.toJSONString(parseResponse(request));
65+
66+
System.out.println(TAG + "parse return response = \n" + response
67+
+ "\n >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
68+
69+
return response;
70+
}
71+
/**解析请求json并获取对应结果
72+
* @param request
6173
* @return requestObject
6274
*/
63-
public JSONObject parse(String json) {
75+
public JSONObject parseResponse(String request) {
6476

6577
try {
66-
json = URLDecoder.decode(json, UTF_8);
78+
request = URLDecoder.decode(request, UTF_8);
6779
} catch (UnsupportedEncodingException e) {
6880
return newErrorResult(e);
6981
}
70-
System.out.println(TAG + "parse json = " + json);
82+
System.out.println("\n\n\n\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n " + TAG + requestMethod.name()
83+
+ "/parseResponse request = " + request);
7184

7285
relationMap = new HashMap<String, String>();
7386
parseRelation = false;
7487
try {
75-
requestObject = getCorrectRequest(requestMethod, JSON.parseObject(json));
88+
requestObject = getCorrectRequest(requestMethod, JSON.parseObject(request));
7689
} catch (Exception e) {
7790
return newErrorResult(e);
7891
}
@@ -98,7 +111,7 @@ public JSONObject parse(String json) {
98111
: extendResult(requestObject, 206, "未完成全部请求:\n" + error.getMessage());
99112
}
100113

101-
// System.out.println(TAG + "\n\n最终返回至客户端的json:\n" + JSON.toJSONString(requestObject));
114+
System.out.println("\n\n\n\n" + TAG + requestMethod.name() + "/parseResponse request = \n" + request);
102115
return requestObject;
103116
}
104117

@@ -313,7 +326,7 @@ public static JSONObject fillTarget(RequestMethod method
313326
}
314327

315328
/**array至少有一个值在request的key中
316-
* @param request
329+
* @param key
317330
* @param array
318331
* @return
319332
*/

APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/server/sql/QueryHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public JSONObject select(QueryConfig config) throws Exception {
146146

147147

148148
/**获取全部字段名列表
149-
* @param table
149+
* @param config
150150
* @return
151151
* @throws SQLException
152152
*/

APIJSON(Server)/APIJSON(Idea)/src/main/java/zuo/biao/apijson/server/Controller.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
import org.springframework.web.bind.annotation.RequestMethod;
2121
import org.springframework.web.bind.annotation.RestController;
2222

23-
import com.alibaba.fastjson.JSONObject;
24-
25-
import zuo.biao.apijson.JSON;
26-
2723
/**request receiver and controller
2824
* @author Lemon
2925
*/
@@ -40,15 +36,24 @@ public String get(@PathVariable String request) {
4036
public String post(@RequestBody String request) {
4137
return new RequestParser(RequestMethod.POST).parse(request);
4238
}
43-
39+
40+
/**用POST方法GET数据,request和response都非明文,浏览器看不到,用于对安全性要求高的GET请求
41+
* @param request
42+
* @return
43+
*/
44+
@RequestMapping(value="post_get", method = RequestMethod.POST)
45+
public String post_get(@RequestBody String request) {
46+
return new RequestParser(RequestMethod.GET).parse(request);
47+
}
48+
4449
/**以下接口继续用POST接口是为了客户端方便,只需要做get,post请求。也可以改用实际对应的方法。
4550
* post,put方法名可以改为add,update等更客户端容易懂的名称
46-
*/
51+
*/
4752
@RequestMapping(value="delete", method = RequestMethod.POST)
4853
public String delete(@RequestBody String request) {
4954
return new RequestParser(RequestMethod.DELETE).parse(request);
5055
}
51-
56+
5257
@RequestMapping(value="put", method = RequestMethod.POST)
5358
public String put(@RequestBody String request) {
5459
return new RequestParser(RequestMethod.PUT).parse(request);

0 commit comments

Comments
 (0)