Skip to content

Commit 01413a5

Browse files
committed
Server:同步eclipse版至idea版
1 parent 0ab8601 commit 01413a5

File tree

8 files changed

+170
-89
lines changed

8 files changed

+170
-89
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
import zuo.biao.apijson.RequestMethod;
4747
import zuo.biao.apijson.RequestRole;
4848
import zuo.biao.apijson.model.Column;
49+
import zuo.biao.apijson.model.Request;
50+
import zuo.biao.apijson.model.Response;
4951
import zuo.biao.apijson.model.Table;
5052
import zuo.biao.apijson.model.Test;
5153
import zuo.biao.apijson.server.JSONRequest;
@@ -76,6 +78,8 @@ public class Verifier {
7678
ACCESS_MAP.put(Table.class.getSimpleName(), getAccessMap(Table.class.getAnnotation(MethodAccess.class)));
7779
ACCESS_MAP.put(Column.class.getSimpleName(), getAccessMap(Column.class.getAnnotation(MethodAccess.class)));
7880
ACCESS_MAP.put(Test.class.getSimpleName(), getAccessMap(Test.class.getAnnotation(MethodAccess.class)));
81+
ACCESS_MAP.put(Request.class.getSimpleName(), getAccessMap(Request.class.getAnnotation(MethodAccess.class)));
82+
ACCESS_MAP.put(Response.class.getSimpleName(), getAccessMap(Response.class.getAnnotation(MethodAccess.class)));
7983

8084
ACCESS_MAP.put(User.class.getSimpleName(), getAccessMap(User.class.getAnnotation(MethodAccess.class)));
8185
ACCESS_MAP.put(Privacy.class.getSimpleName(), getAccessMap(Privacy.class.getAnnotation(MethodAccess.class)));

APIJSON-Java-Server/APIJSON-Idea/src/main/java/zuo/biao/apijson/StringUtil.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -737,23 +737,35 @@ public static String[] split(String s) {
737737
return split(s, null);
738738
}
739739
/**将s用split分割成String[]
740+
* trim = true;
740741
* @param s
741742
* @param split
742743
* @return
743744
*/
744745
public static String[] split(String s, String split) {
746+
return split(s, split, true);
747+
}
748+
/**将s用split分割成String[]
749+
* @param s
750+
* @param split
751+
* @param trim 去掉前后两端的split
752+
* @return
753+
*/
754+
public static String[] split(String s, String split, boolean trim) {
745755
s = getString(s);
746756
if (s.isEmpty()) {
747757
return null;
748758
}
749759
if (isNotEmpty(split, false) == false) {
750760
split = ",";
751761
}
752-
while (s.startsWith(split)) {
753-
s = s.substring(split.length());
754-
}
755-
while (s.endsWith(split)) {
756-
s = s.substring(0, s.length() - split.length());
762+
if (trim) {
763+
while (s.startsWith(split)) {
764+
s = s.substring(split.length());
765+
}
766+
while (s.endsWith(split)) {
767+
s = s.substring(0, s.length() - split.length());
768+
}
757769
}
758770
return s.contains(split) ? s.split(split) : new String[]{s};
759771
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON)
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.*/
14+
15+
package zuo.biao.apijson.model;
16+
17+
import zuo.biao.apijson.MethodAccess;
18+
19+
/**请求类
20+
* @author Lemon
21+
*/
22+
@MethodAccess(
23+
POST = {},
24+
PUT = {},
25+
DELETE = {}
26+
)
27+
public class Request {
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON)
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.*/
14+
15+
package zuo.biao.apijson.model;
16+
17+
import zuo.biao.apijson.MethodAccess;
18+
19+
/**结果类
20+
* @author Lemon
21+
*/
22+
@MethodAccess(
23+
POST = {},
24+
PUT = {},
25+
DELETE = {}
26+
)
27+
public class Response {
28+
}

APIJSON-Java-Server/APIJSON-Idea/src/main/java/zuo/biao/apijson/server/Operation.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON)
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.*/
14+
115
package zuo.biao.apijson.server;
216

317
import zuo.biao.apijson.StringUtil;

APIJSON-Java-Server/APIJSON-Idea/src/main/java/zuo/biao/apijson/server/Parser.java

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -643,11 +643,13 @@ private JSONArray getArray(String parentPath, String name, final JSONObject requ
643643

644644

645645
//key[]:{Table:{}}中key equals Table时 提取Table
646-
boolean isContainer = true;
647646
int index = name == null ? -1 : name.lastIndexOf("[]");
648-
String table = index <= 0 ? null : Pair.parseEntry(name.substring(0, index), true).getKey();
649-
if (JSONRequest.isTableKey(table) && request.containsKey(table)) {
650-
isContainer = false;
647+
String childPath = index <= 0 ? null : Pair.parseEntry(name.substring(0, index), true).getKey(); // Table-key1-key2...
648+
649+
//判断第一个key,即Table是否存在,如果存在就提取
650+
String[] childKeys = StringUtil.split(childPath, "-", false);
651+
if (childKeys == null || childKeys.length <= 0 || request.containsKey(childKeys[0]) == false) {
652+
childKeys = null;
651653
}
652654

653655

@@ -662,7 +664,7 @@ private JSONArray getArray(String parentPath, String name, final JSONObject requ
662664
break;
663665
}
664666
//key[]:{Table:{}}中key equals Table时 提取Table
665-
response.add(isContainer ? parent : parent.getJSONObject(table) );
667+
response.add(getValue(parent, childKeys)); //null有意义
666668
}
667669
//Table>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
668670

@@ -676,6 +678,29 @@ private JSONArray getArray(String parentPath, String name, final JSONObject requ
676678
}
677679

678680

681+
/**根据路径取值
682+
* @param parent
683+
* @param pathKeys
684+
* @return
685+
*/
686+
private static Object getValue(JSONObject parent, String[] pathKeys) {
687+
if (parent == null || pathKeys == null || pathKeys.length <= 0) {
688+
Log.w(TAG, "getChild parent == null || pathKeys == null || pathKeys.length <= 0 >> return parent;");
689+
return parent;
690+
}
691+
692+
//逐层到达child的直接容器JSONObject parent
693+
final int last = pathKeys.length - 1;
694+
for (int i = 0; i < last; i++) {//一步一步到达指定位置
695+
if (parent == null) {//不存在或路径错误(中间的key对应value不是JSONObject)
696+
break;
697+
}
698+
parent = getJSONObject(parent, pathKeys[i]);
699+
}
700+
701+
return parent == null ? null : parent.get(pathKeys[last]);
702+
}
703+
679704

680705
/**获取被依赖引用的key的路径, 实时替换[] -> []/i
681706
* @param parentPath

APIJSON-Java-Server/APIJSON-Idea/src/main/java/zuo/biao/apijson/server/sql/SQLConfig.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
import static zuo.biao.apijson.JSONObject.KEY_CONDITION;
2020
import static zuo.biao.apijson.JSONObject.KEY_GROUP;
2121
import static zuo.biao.apijson.JSONObject.KEY_HAVING;
22+
import static zuo.biao.apijson.JSONObject.KEY_ID;
23+
import static zuo.biao.apijson.JSONObject.KEY_ID_IN;
2224
import static zuo.biao.apijson.JSONObject.KEY_ORDER;
2325
import static zuo.biao.apijson.JSONObject.KEY_ROLE;
2426
import static zuo.biao.apijson.JSONObject.KEY_SCHEMA;
2527
import static zuo.biao.apijson.JSONRequest.KEY_COUNT;
2628
import static zuo.biao.apijson.JSONRequest.KEY_PAGE;
2729
import static zuo.biao.apijson.JSONRequest.KEY_QUERY;
28-
import static zuo.biao.apijson.JSONRequest.KEY_ID;
29-
import static zuo.biao.apijson.JSONRequest.KEY_ID_IN;
3030
import static zuo.biao.apijson.RequestMethod.DELETE;
3131
import static zuo.biao.apijson.RequestMethod.GET;
3232
import static zuo.biao.apijson.RequestMethod.POST;
@@ -54,7 +54,6 @@
5454
import apijson.demo.server.model.BaseModel;
5555
import apijson.demo.server.model.Privacy;
5656
import apijson.demo.server.model.User;
57-
import zuo.biao.apijson.JSONRequest;
5857
import zuo.biao.apijson.Log;
5958
import zuo.biao.apijson.RequestMethod;
6059
import zuo.biao.apijson.RequestRole;
@@ -531,7 +530,7 @@ public static String getWhereString(RequestMethod method, Map<String, Object> wh
531530
continue;
532531
}
533532

534-
whereString += (isFirst ? "" : AND) + condition;
533+
whereString += (isFirst ? "" : AND) + "(" + condition + ")";
535534

536535
isFirst = false;
537536
}
@@ -639,7 +638,7 @@ public static String getSearchString(String key, Object[] values, int type) thro
639638
condition += (i <= 0 ? "" : (Logic.isAnd(type) ? AND : OR)) + getLikeString(key, values[i]);
640639
}
641640

642-
return (Logic.isNot(type) ? NOT : "") + "(" + condition + ")";
641+
return getCondition(Logic.isNot(type), condition);
643642
}
644643

645644
/**WHERE key LIKE 'value'
@@ -693,7 +692,7 @@ public static String getRegExpString(String key, Object[] values, int type) thro
693692
condition += (i <= 0 ? "" : (Logic.isAnd(type) ? AND : OR)) + getRegExpString(key, (String) values[i]);
694693
}
695694

696-
return (Logic.isNot(type) ? NOT : "") + "(" + condition + ")";
695+
return getCondition(Logic.isNot(type), condition);
697696
}
698697

699698
/**WHERE key REGEXP 'value'
@@ -747,8 +746,7 @@ public static String getRangeString(String key, Object range) throws Exception {
747746
if (condition.isEmpty()) {
748747
return "";
749748
}
750-
condition = "(" + condition + ")";
751-
return logic.isNot() ? NOT + condition : condition;
749+
return getCondition(logic.isNot(), condition);
752750
}
753751

754752
throw new IllegalArgumentException(key + "{}:range 类型为" + range.getClass().getSimpleName()
@@ -770,7 +768,7 @@ public static String getInString(String key, Object[] in, boolean not) throws No
770768
throw new NotExistException(TAG + ".getInString(" + key + ", [], " + not
771769
+ ") >> condition.isEmpty() >> IN()");
772770
}
773-
return (not ? NOT : "") + " IN " + "(" + condition + ")";
771+
return (not ? NOT : "") + " IN (" + condition + ")";
774772
}
775773
//{} range >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
776774

@@ -814,7 +812,7 @@ public static String getContainString(String key, Object[] childs, int type) thr
814812
childs[i] = "\"" + childs[i] + "\"";
815813
}
816814
condition += (i <= 0 ? "" : (Logic.isAnd(type) ? AND : OR))
817-
+ getSearchString(
815+
+ "(" + getSearchString(
818816
key
819817
, new String[]{
820818
"[" + childs[i] + "]", //全等
@@ -823,7 +821,7 @@ public static String getContainString(String key, Object[] childs, int type) thr
823821
"%, " + childs[i] + "]" //末尾
824822
}
825823
, Logic.TYPE_OR
826-
);
824+
) + ")";
827825
}
828826
}
829827
if (condition.isEmpty()) {
@@ -833,10 +831,19 @@ public static String getContainString(String key, Object[] childs, int type) thr
833831
if (condition.isEmpty()) {
834832
return "";
835833
}
836-
return (Logic.isNot(type) ? NOT : "") + "(" + condition + ")";
834+
return getCondition(Logic.isNot(type), condition);
837835
}
838836
//<> contain >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
839837

838+
/**拼接条件
839+
* @param not
840+
* @param condition
841+
* @return
842+
*/
843+
private static String getCondition(boolean not, String condition) {
844+
return not ? NOT + "(" + condition + ")" : condition;
845+
}
846+
840847

841848
/**转为JSONArray
842849
* @param tv

0 commit comments

Comments
 (0)