1414
1515package zuo .biao .apijson ;
1616
17+ import java .util .ArrayList ;
1718import java .util .List ;
1819import java .util .Map ;
1920
2526 */
2627public class JSONObject extends com .alibaba .fastjson .JSONObject {
2728 private static final long serialVersionUID = 1L ;
28-
29+
2930 private static final String TAG = "JSONObject" ;
3031
31-
32+
3233 /**ordered
3334 */
3435 public JSONObject () {
@@ -82,9 +83,11 @@ public static boolean isTableKey(String key) {
8283
8384 //JSONObject内关键词 key <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
8485
85-
86- public static final String KEY_ID = "id" ;
87- public static final String KEY_ID_IN = KEY_ID + "{}" ;
86+
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 }
103106
104-
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+ }
121+
122+
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" ; //字段校正
111-
128+
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
@@ -125,33 +157,41 @@ public JSONObject setIdIn(List<Object> list) {
125157 public JSONObject setRole (String role ) {
126158 return puts (KEY_ROLE , role );
127159 }
128-
160+
129161 /**set try, ignore exceptions
130162 * @param tri
131163 * @return this
132164 */
133165 public JSONObject setTry (boolean tri ) {
134166 return puts (KEY_TRY , tri );
135167 }
136-
168+
137169 /**set drop, data dropped will not return
138170 * @param drop
139171 * @return this
140172 */
141173 public JSONObject setDrop (boolean drop ) {
142174 return puts (KEY_DROP , drop );
143175 }
144-
176+
145177 /**set correct, correct keys to target ones
146178 * @param correct Map{originKey, [posibleKeys]}, posibleKey之间用 , 隔开
147179 * @return this
148180 */
149181 public JSONObject setCorrect (Map <String , String > correct ) {
150182 return puts (KEY_CORRECT , correct );
151183 }
184+
185+
152186
153-
154-
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)}
@@ -300,7 +347,7 @@ public JSONObject putsSearch(String key, String value, int type) {
300347
301348 //Request >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
302349
303-
350+
304351
305352 /**puts key-value in object into this
306353 * @param map
@@ -328,7 +375,7 @@ public JSONObject puts(Object value) {
328375 }
329376 /**put and return this
330377 * @param key
331- * @param value
378+ * @param value
332379 * @return this
333380 * @see {@link #put(String, Object)}
334381 */
@@ -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(...) !" );
@@ -370,5 +417,5 @@ public Object put(String key, Object value) {
370417 }
371418
372419
373-
420+
374421}
0 commit comments