@@ -2589,7 +2589,7 @@ else if (id instanceof Subquery) {}
25892589 String [] ws = StringUtil .split (combine );
25902590 if (ws != null ) {
25912591 if (method == DELETE || method == GETS || method == HEADS ) {
2592- throw new IllegalArgumentException ("DELETE,GETS,HEADS 请求不允许传 @combine:\" conditons \" !" );
2592+ throw new IllegalArgumentException ("DELETE,GETS,HEADS 请求不允许传 @combine:value !" );
25932593 }
25942594 whereList = new ArrayList <>();
25952595
@@ -2633,8 +2633,11 @@ else if (w.startsWith("!")) {
26332633
26342634 whereList .add (w );
26352635 }
2636- if (request .containsKey (w ) == false ) {
2637- throw new IllegalArgumentException (table + ":{} 里的 @combine:value 中的value里 " + ws [i ] + " 对应的 " + w + " 不在它里面!" );
2636+
2637+ // 可重写回调方法自定义处理 // 动态设置的场景似乎很少,而且去掉后不方便用户排错!//去掉判断,有时候不在没关系,如果是对增删改等非开放请求强制要求传对应的条件,可以用 Operation.NECESSARY
2638+ if (request .containsKey (w ) == false ) { //和 request.get(w) == null 没区别,前面 Parser 已经过滤了 null
2639+ // throw new IllegalArgumentException(table + ":{} 里的 @combine:value 中的value里 " + ws[i] + " 对应的 " + w + " 不在它里面!");
2640+ callback .onMissingKey4Combine (table , request , combine , ws [i ], w );
26382641 }
26392642 }
26402643
@@ -2931,7 +2934,6 @@ public static interface Callback {
29312934 */
29322935 SQLConfig getSQLConfig (RequestMethod method , String database , String schema , String table );
29332936
2934-
29352937 /**为 post 请求新建 id, 只能是 Long 或 String
29362938 * @param method
29372939 * @param database
@@ -2956,6 +2958,13 @@ public static interface Callback {
29562958 * @return
29572959 */
29582960 String getUserIdKey (String database , String schema , String table );
2961+
2962+ /**combine 里的 key 在 request 中 value 为 null 或不存在,即 request 中缺少用来作为 combine 条件的 key: value
2963+ * @param combine
2964+ * @param key
2965+ * @param request
2966+ */
2967+ public void onMissingKey4Combine (String name , JSONObject request , String combine , String item , String key ) throws Exception ;
29592968 }
29602969
29612970 public static abstract class SimpleCallback implements Callback {
@@ -2975,6 +2984,11 @@ public String getIdKey(String database, String schema, String table) {
29752984 public String getUserIdKey (String database , String schema , String table ) {
29762985 return KEY_USER_ID ;
29772986 }
2987+
2988+ @ Override
2989+ public void onMissingKey4Combine (String name , JSONObject request , String combine , String item , String key ) throws Exception {
2990+ throw new IllegalArgumentException (name + ":{} 里的 @combine:value 中的value里 " + item + " 对应的条件 " + key + ":value 中 value 不能为 null!" );
2991+ }
29782992
29792993 }
29802994
0 commit comments