Skip to content

Commit 1a1195d

Browse files
committed
Server:同步eclipse版至idea版
1 parent 1e20c4d commit 1a1195d

14 files changed

Lines changed: 731 additions & 142 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,11 @@ private JSONObject getObject(String parentPath, final QueryConfig parentConfig,
364364
}
365365
String path = getPath(parentPath, name);
366366

367-
QueryConfig config = StringUtil.isNumer(name) ? parentConfig : null;
367+
boolean nameIsNumber = StringUtil.isNumer(name);
368+
QueryConfig config = nameIsNumber ? parentConfig : null;
368369
if (config == null) {
369370
config = new QueryConfig(requestMethod, name);
370371
}
371-
boolean nameIsNumber = StringUtil.isNumer(name);
372372
final int position = nameIsNumber ? Integer.valueOf(0 + StringUtil.getNumber(name)) : 0;
373373

374374
boolean containRelation = false;
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
package zuo.biao.apijson;
2+
3+
public class Column {
4+
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+
140+
}

APIJSON(Server)/APIJSON(Idea)/src/main/java/zuo/biao/apijson/JSON.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ public static <T> List<T> parseArray(String json, Class<T> clazz) {
119119
* @return
120120
*/
121121
public static String toJSONString(Object obj) {
122+
if (obj instanceof String) {
123+
return (String) obj;
124+
}
122125
try {
123126
return com.alibaba.fastjson.JSON.toJSONString(obj);
124127
} catch (Exception e) {
@@ -133,6 +136,9 @@ public static String toJSONString(Object obj) {
133136
* @return
134137
*/
135138
public static String toJSONString(Object obj, SerializerFeature... features) {
139+
if (obj instanceof String) {
140+
return (String) obj;
141+
}
136142
try {
137143
return com.alibaba.fastjson.JSON.toJSONString(obj, features);
138144
} catch (Exception e) {
@@ -146,7 +152,14 @@ public static String toJSONString(Object obj, SerializerFeature... features) {
146152
* @return
147153
*/
148154
public static String format(String json) {
149-
return toJSONString(parseObject(json), SerializerFeature.PrettyFormat);
155+
return format(parseObject(json));
156+
}
157+
/**格式化,显示更好看
158+
* @param object
159+
* @return
160+
*/
161+
public static String format(JSONObject object) {
162+
return toJSONString(object, SerializerFeature.PrettyFormat);
150163
}
151164

152165

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON)
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.*/
14+
15+
package zuo.biao.apijson;
16+
17+
/**请求方法,对应org.springframework.web.bind.annotation.RequestMethod,多出一个POST_GET方法
18+
* @author Lemon
19+
*/
20+
public enum RequestMethod {
21+
22+
GET, POST_GET, POST, PUT, DELETE
23+
}

APIJSON(Server)/APIJSON(Idea)/src/main/java/zuo/biao/apijson/Table.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
public class Table {
44

55
public static final String ID = "id";
6+
public static final String USER_ID = "userId";
67
public static final String NAME = "name";
78
public static final String SEX = "sex";
89
public static final String PHONE = "phone";

APIJSON(Server)/APIJSON(Idea)/src/main/java/zuo/biao/apijson/server/APIJSONApplication.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import org.springframework.boot.SpringApplication;
1818
import org.springframework.boot.autoconfigure.SpringBootApplication;
1919

20+
import zuo.biao.apijson.server.sql.AccessVerifier;
21+
2022
/**application
2123
* @author Lemon
2224
*/
@@ -25,5 +27,7 @@ public class APIJSONApplication {
2527

2628
public static void main(String[] args) {
2729
SpringApplication.run(APIJSONApplication.class, args);
30+
31+
AccessVerifier.init();
2832
}
2933
}

APIJSON(Server)/APIJSON(Idea)/src/main/java/zuo/biao/apijson/server/ClientTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
package zuo.biao.apijson.server;
1616

17-
import org.springframework.web.bind.annotation.RequestMethod;
17+
import zuo.biao.apijson.RequestMethod;
1818

1919
/**mock test of client
2020
* @author Lemon

APIJSON(Server)/APIJSON(Idea)/src/main/java/zuo/biao/apijson/server/Controller.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,34 +29,34 @@ public class Controller {
2929

3030
@RequestMapping("get/{request}")
3131
public String get(@PathVariable String request) {
32-
return new RequestParser(RequestMethod.GET).parse(request);
32+
return new RequestParser(zuo.biao.apijson.RequestMethod.GET).parse(request);
3333
}
34-
35-
@RequestMapping(value="post", method = RequestMethod.POST)
36-
public String post(@RequestBody String request) {
37-
return new RequestParser(RequestMethod.POST).parse(request);
38-
}
39-
34+
4035
/**用POST方法GET数据,request和response都非明文,浏览器看不到,用于对安全性要求高的GET请求
4136
* @param request
4237
* @return
4338
*/
4439
@RequestMapping(value="post_get", method = RequestMethod.POST)
4540
public String post_get(@RequestBody String request) {
46-
return new RequestParser(RequestMethod.GET).parse(request);
41+
return new RequestParser(zuo.biao.apijson.RequestMethod.POST_GET).parse(request);
4742
}
48-
43+
44+
@RequestMapping(value="post", method = RequestMethod.POST)
45+
public String post(@RequestBody String request) {
46+
return new RequestParser(zuo.biao.apijson.RequestMethod.POST).parse(request);
47+
}
48+
4949
/**以下接口继续用POST接口是为了客户端方便,只需要做get,post请求。也可以改用实际对应的方法。
5050
* post,put方法名可以改为add,update等更客户端容易懂的名称
51-
*/
52-
@RequestMapping(value="delete", method = RequestMethod.POST)
53-
public String delete(@RequestBody String request) {
54-
return new RequestParser(RequestMethod.DELETE).parse(request);
55-
}
56-
51+
*/
5752
@RequestMapping(value="put", method = RequestMethod.POST)
5853
public String put(@RequestBody String request) {
59-
return new RequestParser(RequestMethod.PUT).parse(request);
54+
return new RequestParser(zuo.biao.apijson.RequestMethod.PUT).parse(request);
55+
}
56+
57+
@RequestMapping(value="delete", method = RequestMethod.POST)
58+
public String delete(@RequestBody String request) {
59+
return new RequestParser(zuo.biao.apijson.RequestMethod.DELETE).parse(request);
6060
}
6161

6262
}

0 commit comments

Comments
 (0)