Skip to content

Commit 646bed4

Browse files
committed
解决操作符 UNIQUE 校验不允许重复失效
1 parent 3ccd967 commit 646bed4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -447,14 +447,14 @@ public void verifyRepeat(String table, String key, Object value, long exceptId)
447447
if (exceptId > 0) {//允许修改自己的属性为该属性原来的值
448448
request.put(JSONRequest.KEY_ID + "!", exceptId); // FIXME 这里 id 写死了,不支持自定义
449449
}
450-
JSONObject repeat = createParser().setMethod(GET).setNeedVerify(true).parseResponse(
450+
JSONObject repeat = createParser().setMethod(HEAD).setNeedVerify(true).parseResponse(
451451
new JSONRequest(table, request)
452452
);
453453
repeat = repeat == null ? null : repeat.getJSONObject(table);
454454
if (repeat == null) {
455455
throw new Exception("服务器内部错误 verifyRepeat repeat == null");
456456
}
457-
if (repeat.getIntValue(JSONResponse.KEY_CODE) > 0) {
457+
if (repeat.getIntValue(JSONResponse.KEY_COUNT) > 0) {
458458
throw new ConflictException(key + ": " + value + " 已经存在,不能重复!");
459459
}
460460
}
@@ -1424,7 +1424,7 @@ public static void verifyRepeat(String table, String key, Object value, long exc
14241424

14251425
String finalIdKey = StringUtil.isEmpty(idKey, false) ? apijson.JSONObject.KEY_ID : idKey;
14261426

1427-
SQLConfig config = creator.createSQLConfig().setMethod(RequestMethod.GET).setCount(1).setPage(0);
1427+
SQLConfig config = creator.createSQLConfig().setMethod(RequestMethod.HEAD).setCount(1).setPage(0);
14281428
config.setTable(table);
14291429
if (exceptId > 0) { //允许修改自己的属性为该属性原来的值
14301430
config.putWhere(finalIdKey + "!", exceptId, false);
@@ -1437,7 +1437,7 @@ public static void verifyRepeat(String table, String key, Object value, long exc
14371437
if (result == null) {
14381438
throw new Exception("服务器内部错误 verifyRepeat result == null");
14391439
}
1440-
if (result.getIntValue(JSONResponse.KEY_CODE) > 0) {
1440+
if (result.getIntValue(JSONResponse.KEY_COUNT) > 0) {
14411441
throw new ConflictException(key + ": " + value + " 已经存在,不能重复!");
14421442
}
14431443
} finally {

0 commit comments

Comments
 (0)