Skip to content

Commit 1e20c4d

Browse files
committed
新增where key in(key0, key1...);解决存JSONArray取出变为String;
1 parent 0bffbe0 commit 1e20c4d

6 files changed

Lines changed: 433 additions & 6 deletions

File tree

APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/Column.java

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,139 @@
22

33
public class Column {
44

5+
private int count;//获得所有列的数目及实际列数
6+
private String name;//获得指定列的列名
7+
private String value;//获得指定列的列值
8+
private int type;//获得指定列的数据类型
9+
private String typeName;//获得指定列的数据类型名
10+
private String catalogName;//所在的Catalog名字
11+
private String className;//对应数据类型的类
12+
private int displaySize;//在数据库中类型的最大字符个数
13+
private String label;//默认的列的标题
14+
private String schemaName;//获得列的模式
15+
private int precision;//某列类型的精确度(类型的长度)
16+
private int scale;//小数点后的位数
17+
private String table;//获取某列对应的表名
18+
private boolean autoInctement;// 是否自动递增
19+
private boolean isCurrency;//在数据库中是否为货币型
20+
private int nullable;//是否为空
21+
private boolean readOnly;//是否为只读
22+
private boolean searchable;//能否出现在where中
23+
24+
public Column() {
25+
super();
26+
}
27+
public Column(String name) {
28+
this();
29+
setName(name);
30+
}
31+
public int getCount() {
32+
return count;
33+
}
34+
public void setCount(int count) {
35+
this.count = count;
36+
}
37+
public String getName() {
38+
return name;
39+
}
40+
public void setName(String name) {
41+
this.name = name;
42+
}
43+
public String getValue() {
44+
return value;
45+
}
46+
public void setValue(String value) {
47+
this.value = value;
48+
}
49+
public int getType() {
50+
return type;
51+
}
52+
public void setType(int type) {
53+
this.type = type;
54+
}
55+
public String getTypeName() {
56+
return typeName;
57+
}
58+
public void setTypeName(String typeName) {
59+
this.typeName = typeName;
60+
}
61+
public String getCatalogName() {
62+
return catalogName;
63+
}
64+
public void setCatalogName(String catalogName) {
65+
this.catalogName = catalogName;
66+
}
67+
public String getClassName() {
68+
return className;
69+
}
70+
public void setClassName(String className) {
71+
this.className = className;
72+
}
73+
public int getDisplaySize() {
74+
return displaySize;
75+
}
76+
public void setDisplaySize(int displaySize) {
77+
this.displaySize = displaySize;
78+
}
79+
public String getLabel() {
80+
return label;
81+
}
82+
public void setLabel(String label) {
83+
this.label = label;
84+
}
85+
public String getSchemaName() {
86+
return schemaName;
87+
}
88+
public void setSchemaName(String schemaName) {
89+
this.schemaName = schemaName;
90+
}
91+
public int getPrecision() {
92+
return precision;
93+
}
94+
public void setPrecision(int precision) {
95+
this.precision = precision;
96+
}
97+
public int getScale() {
98+
return scale;
99+
}
100+
public void setScale(int scale) {
101+
this.scale = scale;
102+
}
103+
public String getTable() {
104+
return table;
105+
}
106+
public void setTable(String table) {
107+
this.table = table;
108+
}
109+
public boolean isAutoInctement() {
110+
return autoInctement;
111+
}
112+
public void setAutoInctement(boolean autoInctement) {
113+
this.autoInctement = autoInctement;
114+
}
115+
public boolean getIsCurrency() {
116+
return isCurrency;
117+
}
118+
public void setIsCurrency(boolean isCurrency) {
119+
this.isCurrency = isCurrency;
120+
}
121+
public int getNullable() {
122+
return nullable;
123+
}
124+
public void setNullable(int nullable) {
125+
this.nullable = nullable;
126+
}
127+
public boolean getReadOnly() {
128+
return readOnly;
129+
}
130+
public void setReadOnly(boolean readOnly) {
131+
this.readOnly = readOnly;
132+
}
133+
public boolean getSearchable() {
134+
return searchable;
135+
}
136+
public void setSearchable(boolean searchable) {
137+
this.searchable = searchable;
138+
}
139+
5140
}

APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/server/QueryConfig.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Map;
2020
import java.util.Set;
2121

22+
import com.alibaba.fastjson.JSONArray;
2223
import com.alibaba.fastjson.JSONObject;
2324

2425
import zuo.biao.apijson.RequestMethod;
@@ -113,7 +114,7 @@ public QueryConfig setId(long id) {
113114
this.id = id;
114115
return this;
115116
}
116-
117+
117118
public String getValues() {
118119
return values;
119120
}
@@ -142,6 +143,7 @@ public QueryConfig setWhere(Map<String, Object> where) {
142143
this.where = where;
143144
return this;
144145
}
146+
145147
public int getCount() {
146148
return count;
147149
}
@@ -202,14 +204,17 @@ public static String getWhereString(RequestMethod method, Map<String, Object> wh
202204
&& where.containsKey(Table.ID) == false) {
203205
throw new IllegalArgumentException("请设置" + Table.ID + "!");
204206
}
205-
207+
206208
String whereString = " where ";
209+
Object value;
207210
for (String key : set) {
208211
//避免筛选到全部 value = key == null ? null : where.get(key);
209212
if (key == null) {
210213
continue;
211214
}
212-
whereString += (key + "='" + where.get(key) + "' and ");
215+
value = where.get(key);
216+
whereString += (key + (value instanceof JSONArray
217+
? getInString(((JSONArray)value).toArray()) : "='" + value + "'") + " and ");
213218
}
214219
if (whereString.endsWith("and ")) {
215220
whereString = whereString.substring(0, whereString.length() - "and ".length());
@@ -220,6 +225,22 @@ public static String getWhereString(RequestMethod method, Map<String, Object> wh
220225
}
221226
return "";
222227
}
228+
/**where key in ('key0', 'key1', ... )
229+
* @param in
230+
* @return in ('key0', 'key1', ... )
231+
*/
232+
public static String getInString(Object[] in) {
233+
if (in == null || in.length <= 0) {
234+
return "";
235+
}
236+
String inString = "";
237+
for (int i = 0; i < in.length; i++) {
238+
inString += ((i > 0 ? "," : "") + "'" + in[i] + "'");
239+
}
240+
return " in (" + inString + ") ";
241+
}
242+
243+
223244
/**获取筛选方法
224245
* @return
225246
*/

APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/server/RequestParser.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,11 +599,14 @@ private String getPath(String path, String name) {
599599
* @return
600600
*/
601601
private boolean isInRelationMap(String path) {
602+
if (path == null) {
603+
return false;
604+
}
602605
// return relationMap == null ? false : relationMap.containsKey(path);
603606
Set<String> set = relationMap == null ? null : relationMap.keySet();
604607
if (set != null) {
605608
for (String key : set) {
606-
if (key != null && key.contains(path)) {
609+
if (path.equals(key) || key.startsWith(path + "/")) {//解决相同字符导致的错误) {//key.contains(path)) {//
607610
return true;
608611
}
609612
}

APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/server/sql/AccessVerifier.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public static JSONObject removeAccessInfo(JSONObject requestObject) {
218218
*/
219219
public static boolean verifyMethod(String table, RequestMethod method) throws AccessException {
220220
RequestMethod[] methods = table == null ? null : accessMap.get(table);
221-
if (methods == null) {
221+
if (methods == null || methods.length <= 0) {
222222
throw new AccessException(table + "不允许访问!");
223223
}
224224
if (method == null) {

APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/server/sql/QueryHelper.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.ArrayList;
2424
import java.util.List;
2525

26+
import com.alibaba.fastjson.JSON;
2627
import com.alibaba.fastjson.JSONObject;
2728

2829
import zuo.biao.apijson.StringUtil;
@@ -132,8 +133,22 @@ public JSONObject select(QueryConfig config) throws Exception {
132133
}
133134
object = new JSONObject(true);
134135
try {
136+
Object value;
137+
Object json;
135138
for (int i = 0; i < columnArray.length; i++) {
136-
object.put(columnArray[i], rs.getObject(rs.findColumn(columnArray[i])));
139+
value = rs.getObject(rs.findColumn(columnArray[i]));
140+
if (value instanceof String) {
141+
try {
142+
json = JSON.parse((String) value);
143+
if (json != null && StringUtil.isNotEmpty(json, true)) {
144+
value = json;
145+
}
146+
} catch (Exception e) {
147+
// System.out.println(TAG + "select while (rs.next()){ >> i = " + i + " try { json = JSON.parse((String) value);"
148+
// + ">> } catch (Exception e) {\n" + e.getMessage());
149+
}
150+
}
151+
object.put(columnArray[i], value);
137152
}
138153
} catch (Exception e) {
139154
System.out.println(TAG + "select while (rs.next()){ ... >> try { object.put(list.get(i), ..." +

0 commit comments

Comments
 (0)