Skip to content

Commit 7c9ca1b

Browse files
committed
Operation 操作方式新增 IS_ID_CONDITION_MUST,是否强制要求必须有 id/id{}/id{}@ 条件
1 parent 6e95be6 commit 7c9ca1b

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

APIJSONORM/src/main/java/apijson/RequestMethod.java

+16
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ public static boolean isHeadMethod(RequestMethod method, boolean containPrivate)
8383
public static boolean isQueryMethod(RequestMethod method) {
8484
return isGetMethod(method, true) || isHeadMethod(method, true);
8585
}
86+
87+
/**是否为更新(增删改)的请求方法
88+
* @param method
89+
* @return 读操作(GET型或HEAD型) - false, 写操作(POST,PUT,DELETE) - true
90+
*/
91+
public static boolean isUpdateMethod(RequestMethod method) {
92+
return ! isQueryMethod(method);
93+
}
8694

8795
/**是否为开放(不限制请求的结构或内容;明文,浏览器能直接访问及查看)的请求方法
8896
* @param method
@@ -92,6 +100,14 @@ public static boolean isPublicMethod(RequestMethod method) {
92100
return method == null || method == GET || method == HEAD;
93101
}
94102

103+
/**是否为私有(限制请求的结构或内容)的请求方法
104+
* @param method
105+
* @return
106+
*/
107+
public static boolean isPrivateMethod(RequestMethod method) {
108+
return ! isPublicMethod(method);
109+
}
110+
95111
public static String getName(RequestMethod method) {
96112
return method == null ? GET.name() : method.name();
97113
}

APIJSONORM/src/main/java/apijson/orm/AbstractVerifier.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
public abstract class AbstractVerifier<T extends Object> implements Verifier<T>, IdCallback<T> {
8181
private static final String TAG = "AbstractVerifier";
8282

83-
/**为 PUT, DELETE 强制要求必须有 id/id{} 条件
83+
/**为 PUT, DELETE 强制要求必须有 id/id{}/id{}@ 条件
8484
*/
8585
public static boolean IS_UPDATE_MUST_HAVE_ID_CONDITION = true;
8686
/**开启校验请求角色权限
@@ -700,8 +700,9 @@ public JSONObject onParseJSONObject(String key, JSONObject tobj, JSONObject robj
700700
throw new IllegalArgumentException(method + "请求," + name + "/" + key + " 不能传 " + finalIdKey + " !");
701701
}
702702
} else {
703-
if (RequestMethod.isQueryMethod(method) == false) {
704-
verifyId(method.name(), name, key, robj, finalIdKey, maxUpdateCount, IS_UPDATE_MUST_HAVE_ID_CONDITION);
703+
Boolean atLeastOne = tobj == null ? null : tobj.getBoolean(Operation.IS_ID_CONDITION_MUST.name());
704+
if (Boolean.TRUE.equals(atLeastOne) || RequestMethod.isUpdateMethod(method)) {
705+
verifyId(method.name(), name, key, robj, finalIdKey, maxUpdateCount, atLeastOne != null ? atLeastOne : IS_UPDATE_MUST_HAVE_ID_CONDITION);
705706

706707
String userIdKey = idCallback == null ? null : idCallback.getUserIdKey(db, sh, ds, key);
707708
String finalUserIdKey = StringUtil.isEmpty(userIdKey, false) ? apijson.JSONObject.KEY_USER_ID : userIdKey;
@@ -746,7 +747,7 @@ private static void verifyId(@NotNull String method, @NotNull String name, @NotN
746747
Object id = robj.get(idKey); //如果必须传 id ,可在Request表中配置NECESSARY
747748
if (id != null && id instanceof Number == false && id instanceof String == false) {
748749
throw new IllegalArgumentException(method + "请求," + name + "/" + key
749-
+ " 里面的 " + idKey + ":value 中value的类型只能是 Long 或 String !");
750+
+ " 里面的 " + idKey + ":value 中value的类型只能是 Long 或 String !");
750751
}
751752

752753

@@ -795,7 +796,7 @@ else if (o instanceof String) {
795796
}
796797
else {
797798
throw new IllegalArgumentException(method + "请求," + name + "/" + key
798-
+ " 里面的 " + idInKey + ":[] 中所有项的类型都只能是 Long 或 String !");
799+
+ " 里面的 " + idInKey + ":[] 中所有项的类型都只能是 Long 或 String !");
799800
}
800801
}
801802
}

APIJSONORM/src/main/java/apijson/orm/Operation.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,13 @@ public enum Operation {
145145
/**
146146
* 允许批量增删改部分失败,结构是
147147
* "Table[],key[],key:alias[]"
148-
* 自动 ALLOW_PARTIAL_UPDATE_FAILED_TABLE_MAP.put
148+
* 自动 ALLOW_PARTIAL_UPDATE_FAILED_TABLE_MAP.put,结构是 Boolean,例如 true
149149
*/
150-
ALLOW_PARTIAL_UPDATE_FAIL;
150+
ALLOW_PARTIAL_UPDATE_FAIL,
151+
152+
/**
153+
* 强制要求必须有 id/id{}/id{}@ 条件,结构是 Boolean,例如 true
154+
*/
155+
IS_ID_CONDITION_MUST;
151156

152157
}

0 commit comments

Comments
 (0)