Skip to content

Commit a6b0a8d

Browse files
committed
Server:与Client同步SQL,JSON,JSONObject,JSONRequest,JSONResponse,
1 parent 489ede1 commit a6b0a8d

File tree

5 files changed

+363
-140
lines changed

5 files changed

+363
-140
lines changed

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
import zuo.biao.apijson.server.Log;
2525

26-
/**阿里json封装类 防止解析时异常
26+
/**阿里FastJSON封装类 防止解析时异常
2727
* @author Lemon
2828
*/
2929
public class JSON {
@@ -34,7 +34,7 @@ public class JSON {
3434
* @return
3535
*/
3636
public static boolean isJsonCorrect(String s) {
37-
Log.i(TAG, "isJsonCorrect <<<< " + s + " >>>>>>>");
37+
// Log.i(TAG, "isJsonCorrect <<<< " + s + " >>>>>>>");
3838
if (s == null
3939
// || s.equals("[]")
4040
// || s.equals("{}")
@@ -171,7 +171,7 @@ public static String toJSONString(Object obj) {
171171
try {
172172
return com.alibaba.fastjson.JSON.toJSONString(obj);
173173
} catch (Exception e) {
174-
Log.i(TAG, "toJSONString catch \n" + e.getMessage());
174+
Log.e(TAG, "toJSONString catch \n" + e.getMessage());
175175
}
176176
return null;
177177
}
@@ -188,7 +188,7 @@ public static String toJSONString(Object obj, SerializerFeature... features) {
188188
try {
189189
return com.alibaba.fastjson.JSON.toJSONString(obj, features);
190190
} catch (Exception e) {
191-
Log.i(TAG, "toJSONString catch \n" + e.getMessage());
191+
Log.e(TAG, "parseArray catch \n" + e.getMessage());
192192
}
193193
return null;
194194
}
@@ -221,9 +221,7 @@ public static boolean isJSONObject(Object obj) {
221221
JSONObject json = parseObject((String) obj);
222222
return json != null && json.isEmpty() == false;
223223
} catch (Exception e) {
224-
//太长 System.out.println(TAG + "select while (rs.next()){ >> i = "
225-
// + i + " try { json = JSON.parse((String) value);"
226-
// + ">> } catch (Exception e) {\n" + e.getMessage());
224+
Log.e(TAG, "isJSONObject catch \n" + e.getMessage());
227225
}
228226
}
229227

@@ -242,14 +240,11 @@ public static boolean isJSONArray(Object obj) {
242240
JSONArray json = parseArray((String) obj);
243241
return json != null && json.isEmpty() == false;
244242
} catch (Exception e) {
245-
//太长 System.out.println(TAG + "select while (rs.next()){ >> i = "
246-
// + i + " try { json = JSON.parse((String) value);"
247-
// + ">> } catch (Exception e) {\n" + e.getMessage());
243+
Log.e(TAG, "isJSONArray catch \n" + e.getMessage());
248244
}
249245
}
250246

251247
return false;
252248
}
253249

254-
255250
}

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

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,114 @@ public String getColumns() {
243243
}
244244

245245

246+
247+
248+
//Request,默认encode <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
249+
250+
/**
251+
* encode = true
252+
* @param key
253+
* @param isNull
254+
* @return {@link #putNull(String, boolean, boolean)}
255+
*/
256+
public JSONObject putNull(String key, boolean isNull) {
257+
return putNull(key, isNull, true);
258+
}
259+
/**
260+
* @param key
261+
* @param isNull
262+
* @param encode
263+
* @return
264+
*/
265+
public JSONObject putNull(String key, boolean isNull, boolean encode) {
266+
put(key + "{}", SQL.isNull(isNull), encode);
267+
return this;
268+
}
269+
/**
270+
* trim = false
271+
* @param key
272+
* @param isEmpty
273+
* @return {@link #putEmpty(String, boolean, boolean)}
274+
*/
275+
public JSONObject putEmpty(String key, boolean isEmpty) {
276+
return putEmpty(key, isEmpty, false);
277+
}
278+
/**
279+
* encode = true
280+
* @param key
281+
* @param isEmpty
282+
* @return {@link #putEmpty(String, boolean, boolean, boolean)}
283+
*/
284+
public JSONObject putEmpty(String key, boolean isEmpty, boolean trim) {
285+
return putEmpty(key, isEmpty, trim, true);
286+
}
287+
/**
288+
* @param key
289+
* @param isEmpty
290+
* @param encode
291+
* @return
292+
*/
293+
public JSONObject putEmpty(String key, boolean isEmpty, boolean trim, boolean encode) {
294+
put(key + "{}", SQL.isEmpty(key, isEmpty, trim), encode);
295+
return this;
296+
}
297+
/**
298+
* encode = true
299+
* @param key
300+
* @param compare <=0, >5 ...
301+
* @return {@link #putLength(String, String, boolean)}
302+
*/
303+
public JSONObject putLength(String key, String compare) {
304+
return putLength(key, compare, true);
305+
}
306+
/**
307+
* @param key
308+
* @param compare <=0, >5 ...
309+
* @param encode
310+
* @return
311+
*/
312+
public JSONObject putLength(String key, String compare, boolean encode) {
313+
put(key + "{}", SQL.length(key) + compare, encode);
314+
return this;
315+
}
316+
317+
/**设置搜索
318+
* type = SEARCH_TYPE_CONTAIN_FULL
319+
* @param key
320+
* @param value
321+
* @return {@link #putSearch(String, String, int)}
322+
*/
323+
public JSONObject putSearch(String key, String value) {
324+
return putSearch(key, value, SQL.SEARCH_TYPE_CONTAIN_FULL);
325+
}
326+
/**设置搜索
327+
* encode = true
328+
* @param key
329+
* @param value
330+
* @param type
331+
* @return {@link #putSearch(String, String, int, boolean)}
332+
*/
333+
public JSONObject putSearch(String key, String value, int type) {
334+
return putSearch(key, value, type, true);
335+
}
336+
/**设置搜索
337+
* @param key
338+
* @param value
339+
* @param type
340+
* @param encode
341+
* @return
342+
*/
343+
public JSONObject putSearch(String key, String value, int type, boolean encode) {
344+
if (key == null) {
345+
key = "";
346+
}
347+
if (key.endsWith("$") == false) {
348+
key += "$";
349+
}
350+
put(key, SQL.search(value, type), encode);
351+
return this;
352+
}
353+
354+
//Request,默认encode >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
355+
246356
}

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

Lines changed: 0 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ public String getTag() {
8484

8585
public static final String KEY_COUNT = "count";
8686
public static final String KEY_PAGE = "page";
87-
public static final String KEY_TOTAL = "total";
8887

8988
public JSONRequest setCount(int count) {
9089
put(KEY_COUNT, count);
@@ -101,15 +100,6 @@ public JSONRequest setPage(int page) {
101100
public int getPage() {
102101
return getIntValue(KEY_PAGE);
103102
}
104-
// private int total;
105-
public JSONRequest setTotal(int total) {
106-
// this.total = total;
107-
put(KEY_TOTAL, total);
108-
return this;
109-
}
110-
public int getTotal() {
111-
return getIntValue(KEY_TOTAL);//total;//
112-
}
113103
//array object >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
114104

115105

@@ -201,120 +191,4 @@ public JSONRequest toArray(int count, int page, String name, boolean encode) {
201191
return new JSONRequest(StringUtil.getString(name) + KEY_ARRAY, this.setCount(count).setPage(page), encode);
202192
}
203193

204-
205-
/**设置搜索
206-
* @param key
207-
* @param value
208-
* @see {@link #putSearch(String, String, int)}
209-
*/
210-
public void putSearch(String key, String value) {
211-
putSearch(key, value, SEARCH_TYPE_CONTAIN_FULL);
212-
}
213-
/**设置搜索
214-
* encode = true
215-
* @param key
216-
* @param value
217-
* @param type
218-
* @see {@link #putSearch(String, String, int, boolean)}
219-
*/
220-
public void putSearch(String key, String value, int type) {
221-
putSearch(key, value, type, true);
222-
}
223-
/**设置搜索
224-
* @param key
225-
* @param value
226-
* @param type
227-
* @param encode
228-
*/
229-
public void putSearch(String key, String value, int type, boolean encode) {
230-
if (key == null) {
231-
key = "";
232-
}
233-
if (key.endsWith("$") == false) {
234-
key += "$";
235-
}
236-
put(key, getSearch(value, type), encode);
237-
}
238-
239-
public static final int SEARCH_TYPE_CONTAIN_FULL = 0;
240-
public static final int SEARCH_TYPE_CONTAIN_ORDER = 1;
241-
public static final int SEARCH_TYPE_CONTAIN_SINGLE = 2;
242-
public static final int SEARCH_TYPE_CONTAIN_ANY = 3;
243-
public static final int SEARCH_TYPE_START = 4;
244-
public static final int SEARCH_TYPE_END = 5;
245-
public static final int SEARCH_TYPE_START_SINGLE = 6;
246-
public static final int SEARCH_TYPE_END_SINGLE = 7;
247-
public static final int SEARCH_TYPE_PART_MATCH = 8;
248-
/**
249-
* SQL中NOT LIKE就行??
250-
*/
251-
public static final int SEARCH_TYPE_NO_CONTAIN = 9;
252-
/**
253-
* SQL中NOT LIKE就行??
254-
*/
255-
public static final int SEARCH_TYPE_NO_PART_MATCH = 10;
256-
/**获取搜索值
257-
* @param key
258-
* @return
259-
*/
260-
public static String getSearch(String key) {
261-
return getSearch(key, SEARCH_TYPE_CONTAIN_FULL);
262-
}
263-
/**获取搜索值
264-
* @param key
265-
* @param type
266-
* @return
267-
*/
268-
public static String getSearch(String key, int type) {
269-
return getSearch(key, type, true);
270-
}
271-
/**获取搜索值
272-
* @param key
273-
* @param type
274-
* @param ignoreCase
275-
* @return
276-
*/
277-
public static String getSearch(String key, int type, boolean ignoreCase) {
278-
if (key == null) {
279-
return null;
280-
}
281-
switch (type) {
282-
case SEARCH_TYPE_CONTAIN_SINGLE:
283-
return "_" + key + "_";
284-
case SEARCH_TYPE_CONTAIN_ORDER:
285-
char[] cs = key.toCharArray();
286-
if (cs == null) {
287-
return null;
288-
}
289-
String s = "%";
290-
for (int i = 0; i < cs.length; i++) {
291-
s += cs[i] + "%";
292-
}
293-
return s;
294-
case SEARCH_TYPE_START:
295-
return key + "%";
296-
case SEARCH_TYPE_END:
297-
return "%" + key;
298-
case SEARCH_TYPE_START_SINGLE:
299-
return key + "_";
300-
case SEARCH_TYPE_END_SINGLE:
301-
return "_" + key;
302-
case SEARCH_TYPE_NO_CONTAIN:
303-
return "[^" + key + "]";
304-
case SEARCH_TYPE_NO_PART_MATCH:
305-
cs = key.toCharArray();
306-
if (cs == null) {
307-
return null;
308-
}
309-
s = "";
310-
for (int i = 0; i < cs.length; i++) {
311-
s += getSearch("" + cs[i], SEARCH_TYPE_NO_CONTAIN, ignoreCase);
312-
}
313-
return s;
314-
default:
315-
return "%" + key + "%";
316-
}
317-
}
318-
319-
320194
}

0 commit comments

Comments
 (0)