1414
1515package zuo .biao .apijson ;
1616
17+ import java .util .ArrayList ;
1718import java .util .List ;
1819import java .util .Map ;
1920
@@ -36,21 +37,21 @@ public JSONObject() {
3637 }
3738 /**transfer Object to JSONObject
3839 * @param object
39- * @see {@link #JSONObject(Object, boolean )}
40+ * @see {@link #JSONObject(Object)}
4041 */
4142 public JSONObject (Object object ) {
4243 this (toJSONString (object ));
4344 }
4445 /**parse JSONObject with JSON String
4546 * @param json
46- * @see {@link #JSONObject(String, boolean )}
47+ * @see {@link #JSONObject(String)}
4748 */
4849 public JSONObject (String json ) {
4950 this (parseObject (json ));
5051 }
5152 /**transfer com.alibaba.fastjson.JSONObject to JSONObject
5253 * @param object
53- * @see {@link #putsAll(com.alibaba.fastjson.JSONObject )}
54+ * @see {@link #putsAll(Map<? extends String, ? extends Object> )}
5455 */
5556 public JSONObject (com .alibaba .fastjson .JSONObject object ) {
5657 this ();
@@ -83,8 +84,10 @@ public static boolean isTableKey(String key) {
8384 //JSONObject内关键词 key <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
8485
8586
86- public static final String KEY_ID = "id" ;
87- public static final String KEY_ID_IN = KEY_ID + "{}" ;
87+ public static String KEY_ID = "id" ;
88+ public static String KEY_ID_IN = KEY_ID + "{}" ;
89+ public static String KEY_USER_ID = "userId" ;
90+ public static String KEY_USER_ID_IN = KEY_USER_ID + "{}" ;
8891
8992 /**set "id":id in Table layer
9093 * @param id
@@ -93,28 +96,57 @@ public static boolean isTableKey(String key) {
9396 public JSONObject setId (Long id ) {
9497 return puts (KEY_ID , id );
9598 }
96- /**set id{}:[] in Table layer
99+ /**set " id{}" :[] in Table layer
97100 * @param list
98101 * @return
99102 */
100103 public JSONObject setIdIn (List <Object > list ) {
101104 return puts (KEY_ID_IN , list );
102105 }
106+
107+ /**set "userId":userId in Table layer
108+ * @param id
109+ * @return
110+ */
111+ public JSONObject setUserId (Long id ) {
112+ return puts (KEY_USER_ID , id );
113+ }
114+ /**set "userId{}":[] in Table layer
115+ * @param list
116+ * @return
117+ */
118+ public JSONObject setUserIdIn (List <Object > list ) {
119+ return puts (KEY_USER_ID_IN , list );
120+ }
103121
104122
105123 //@key关键字都放这个类 <<<<<<<<<<<<<<<<<<<<<<
106124 public static final String KEY_ROLE = "@role" ; //角色,拥有对某些数据的某些操作的权限
107- public static final String KEY_CONDITION = "@condition" ; //条件 TODO 用 @where& @where| @where! 替代?
108125 public static final String KEY_TRY = "@try" ; //尝试,忽略异常
109126 public static final String KEY_DROP = "@drop" ; //丢弃,不返回
110127 public static final String KEY_CORRECT = "@correct" ; //字段校正
111128
129+ public static final String KEY_DATABASE = "@database" ; //数据库类型,默认为MySQL
112130 public static final String KEY_SCHEMA = "@schema" ; //数据库,Table在非默认schema内时需要声明
113- public static final String KEY_ABOUT = "@about" ; //关于,返回数据库表的信息,包括表说明和字段说明
114131 public static final String KEY_COLUMN = "@column" ; //查询的Table字段或SQL函数
132+ public static final String KEY_COMBINE = "@combine" ; //条件组合,每个条件key前面可以放&,|,!逻辑关系 "id!{},&sex,!name&$"
115133 public static final String KEY_GROUP = "@group" ; //分组方式
116134 public static final String KEY_HAVING = "@having" ; //聚合函数条件,一般和@group一起用
117135 public static final String KEY_ORDER = "@order" ; //排序方式
136+
137+ public static final List <String > TABLE_KEY_LIST ;
138+ static {
139+ TABLE_KEY_LIST = new ArrayList <String >();
140+ TABLE_KEY_LIST .add (KEY_ROLE );
141+ TABLE_KEY_LIST .add (KEY_DATABASE );
142+ TABLE_KEY_LIST .add (KEY_SCHEMA );
143+ TABLE_KEY_LIST .add (KEY_COLUMN );
144+ TABLE_KEY_LIST .add (KEY_COMBINE );
145+ TABLE_KEY_LIST .add (KEY_GROUP );
146+ TABLE_KEY_LIST .add (KEY_HAVING );
147+ TABLE_KEY_LIST .add (KEY_ORDER );
148+ }
149+
118150 //@key关键字都放这个类 >>>>>>>>>>>>>>>>>>>>>>
119151
120152
@@ -152,6 +184,14 @@ public JSONObject setCorrect(Map<String, String> correct) {
152184
153185
154186
187+ /**set database where table was puts
188+ * @param database
189+ * @return this
190+ */
191+ public JSONObject setDatabase (String database ) {
192+ return puts (KEY_DATABASE , database );
193+
194+ }
155195 /**set schema where table was puts
156196 * @param schema
157197 * @return this
@@ -160,14 +200,6 @@ public JSONObject setSchema(String schema) {
160200 return puts (KEY_SCHEMA , schema );
161201 }
162202
163- /**set about
164- * @param about
165- * @return this
166- */
167- public JSONObject setAbout (boolean about ) {
168- return puts (KEY_ABOUT , about );
169- }
170-
171203 /**set keys need to be returned
172204 * @param keys key0, key1, key2 ...
173205 * @return {@link #setColumn(String)}
@@ -183,6 +215,21 @@ public JSONObject setColumn(String keys) {
183215 return puts (KEY_COLUMN , keys );
184216 }
185217
218+ /**set combination of keys for conditions
219+ * @param keys key0,&key1,|key2,!kye3 ...
220+ * @return {@link #setColumn(String)}
221+ */
222+ public JSONObject setCombine (String ... keys ) {
223+ return setCombine (StringUtil .getString (keys , true ));
224+ }
225+ /**set combination of keys for conditions
226+ * @param keys key0,&key1,|key2,!kye3 ...
227+ * @return
228+ */
229+ public JSONObject setCombine (String keys ) {
230+ return puts (KEY_COMBINE , keys );
231+ }
232+
186233 /**set keys for group by
187234 * @param keys key0, key1, key2 ...
188235 * @return {@link #setGroup(String)}
@@ -303,7 +350,7 @@ public JSONObject putsSearch(String key, String value, int type) {
303350
304351
305352 /**puts key-value in object into this
306- * @param object
353+ * @param map
307354 * @return this
308355 */
309356 public JSONObject putsAll (Map <? extends String , ? extends Object > map ) {
@@ -318,10 +365,10 @@ public void putAll(Map<? extends String, ? extends Object> map) {
318365 }
319366
320367
321-
368+
322369 /**put and return this
323370 * @param value must be annotated by {@link MethodAccess}
324- * @return {@link #puts(String, boolean )}
371+ * @return {@link #puts(String, Object )}
325372 */
326373 public JSONObject puts (Object value ) {
327374 return puts (null , value );
@@ -336,10 +383,10 @@ public JSONObject puts(String key, Object value) {
336383 put (key , value );
337384 return this ;
338385 }
339-
386+
340387 /**put and return value
341388 * @param value must be annotated by {@link MethodAccess}
342- * @return {@link #put(String, boolean )}
389+ * @return {@link #put(String, Object )}
343390 */
344391 public Object put (Object value ) {
345392 return put (null , value );
@@ -356,10 +403,10 @@ public Object put(String key, Object value) {
356403 return null ;
357404 }
358405 if (StringUtil .isEmpty (key , true )) {
359- Class <?> clazz = value .getClass ();
360- if (clazz == null || clazz .getAnnotation (MethodAccess .class ) == null ) {
361- throw new IllegalArgumentException ("puts StringUtil.isNotEmpty (key, true) == false " +
362- " && clazz == null || clazz.getAnnotation(MethodAccess.class) == null" +
406+ Class <?> clazz = value .getClass (); //should not return null
407+ if (clazz .getAnnotation (MethodAccess .class ) == null ) {
408+ throw new IllegalArgumentException ("puts StringUtil.isEmpty (key, true)" +
409+ " clazz.getAnnotation(MethodAccess.class) == null" +
363410 " \n key为空时仅支持 类型被@MethodAccess注解 的value !!!" +
364411 " \n 如果一定要这么用,请对 " + clazz .getName () + " 注解!" +
365412 " \n 如果是类似 key[]:{} 结构的请求,建议用 putsAll(...) !" );
0 commit comments