Skip to content

Commit 15c57dc

Browse files
committed
Server:Parser新增noVerify免验证并优化Controller;新增ExceptionUtil和StructureVerifier;优化model的注解和注释;去除多余代码;优化其它类注释
1 parent 666ae3a commit 15c57dc

22 files changed

+760
-225
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@
3333
*/
3434
RequestMethod[] method() default {};
3535

36-
37-
/**@see {@link RequestMethod#POST_GET}
38-
* @return 该请求方法允许的结构
39-
*/
40-
String POST_GET() default "";
4136

4237
/**@see {@link RequestMethod#POST_HEAD}
4338
* @return 该请求方法允许的结构
4439
*/
4540
String POST_HEAD() default "";
41+
42+
/**@see {@link RequestMethod#POST_GET}
43+
* @return 该请求方法允许的结构
44+
*/
45+
String POST_GET() default "";
4646

4747
/**@see {@link RequestMethod#POST}
4848
* @return 该请求方法允许的结构

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ public String delete(@RequestBody String request) {
104104

105105
@RequestMapping("post/authCode/{phone}")
106106
public String postAuthCode(@PathVariable String phone) {
107-
new Parser(RequestMethod.DELETE).parse(newVerifyRequest(newVerify(phone, 0)));
107+
new Parser(RequestMethod.DELETE, true).parse(newVerifyRequest(newVerify(phone, 0)));
108108

109-
JSONObject response = new Parser(RequestMethod.POST).parseResponse(
109+
JSONObject response = new Parser(RequestMethod.POST, true).parseResponse(
110110
newVerifyRequest(newVerify(phone, new Random().nextInt(9999) + 1000)));
111111

112112
JSONObject verify = null;
@@ -116,7 +116,7 @@ public String postAuthCode(@PathVariable String phone) {
116116
// TODO: handle exception
117117
}
118118
if (verify == null || verify.getIntValue("status") != 200) {
119-
new Parser(RequestMethod.DELETE).parseResponse(new JSONRequest(new Verify(phone)));
119+
new Parser(RequestMethod.DELETE, true).parseResponse(new JSONRequest(new Verify(phone)));
120120
return JSON.toJSONString(Parser.extendErrorResult(response, null));
121121
}
122122

@@ -139,12 +139,12 @@ public String checkAuthCode(@PathVariable String phone, @PathVariable String cod
139139
* @return
140140
*/
141141
public JSONObject checkVerify(String phone, String code) {
142-
JSONResponse response = new JSONResponse(new Parser(RequestMethod.POST_GET).parseResponse(new JSONRequest(
143-
new Verify(phone)).setTag(Verify.class.getSimpleName())));
142+
JSONResponse response = new JSONResponse(new Parser(RequestMethod.POST_GET, true)
143+
.parseResponse(new JSONRequest(new Verify(phone)).setTag(Verify.class.getSimpleName())));
144144
Verify verify = response.getObject(Verify.class);
145145
//验证码过期
146146
if (verify != null && System.currentTimeMillis() - verify.getDate() > 60000) {
147-
new Parser(RequestMethod.DELETE).parseResponse(new JSONRequest(new Verify(phone))
147+
new Parser(RequestMethod.DELETE, true).parseResponse(new JSONRequest(new Verify(phone))
148148
.setTag(Verify.class.getSimpleName()));
149149
return Parser.newErrorResult(new TimeoutException("验证码已过期!"));
150150
}
@@ -191,7 +191,7 @@ public String login(@PathVariable String typeString, @PathVariable String phone,
191191
//校验凭证
192192
int type = Integer.valueOf(0 + StringUtil.getNumber(typeString));
193193
if (type == Login.TYPE_PASSWORD) {//password
194-
response = new JSONResponse(new Parser(RequestMethod.HEAD).parseResponse(
194+
response = new JSONResponse(new Parser(RequestMethod.POST_HEAD).parseResponse(
195195
new JSONRequest(new Password(User.class.getSimpleName(), phone, password))));
196196
} else {//verify
197197
response = new JSONResponse(checkVerify(phone, password));
@@ -214,9 +214,9 @@ public String login(@PathVariable String typeString, @PathVariable String phone,
214214
return JSON.toJSONString(Parser.extendErrorResult(result, null));
215215
}
216216
//删除Login
217-
new Parser(RequestMethod.DELETE).parseResponse(new JSONRequest(new Login().setUserId(user.getId())));
217+
new Parser(RequestMethod.DELETE, true).parseResponse(new JSONRequest(new Login().setUserId(user.getId())));
218218
//写入Login
219-
new Parser(RequestMethod.POST).parseResponse(new JSONRequest(
219+
new Parser(RequestMethod.POST, true).parseResponse(new JSONRequest(
220220
new Login().setType(type).setUserId(user.getId())));
221221

222222
return JSON.toJSONString(result);
@@ -270,18 +270,18 @@ public String register(@RequestBody String request) {
270270
}
271271

272272
//生成User
273-
JSONObject result = new Parser(RequestMethod.POST).parseResponse(requestObject);
273+
JSONObject result = new Parser(RequestMethod.POST, true).parseResponse(requestObject);
274274
response = new JSONResponse(result);
275275
if (JSONResponse.isSucceed(response) == false) {
276276
return JSON.toJSONString(Parser.extendErrorResult(result, null));
277277
}
278278

279279
//生成Password
280-
response = new JSONResponse(new Parser(RequestMethod.POST).parseResponse(
280+
response = new JSONResponse(new Parser(RequestMethod.POST, true).parseResponse(
281281
new JSONRequest(new Password(User.class.getSimpleName(), phone, password))));
282282
if (JSONResponse.isSucceed(response.getJSONResponse(Password.class.getSimpleName())) == false) {
283-
new Parser(RequestMethod.DELETE).parseResponse(new JSONRequest(new User().setPhone(phone)));
284-
new Parser(RequestMethod.DELETE).parseResponse(new JSONRequest(new Password().setPhone(phone)));
283+
new Parser(RequestMethod.DELETE, true).parseResponse(new JSONRequest(new User().setPhone(phone)));
284+
new Parser(RequestMethod.DELETE, true).parseResponse(new JSONRequest(new Password().setPhone(phone)));
285285
return JSON.toJSONString(Parser.extendErrorResult(result, null));
286286
}
287287

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

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
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+
115
package zuo.biao.apijson.server;
216

317
import java.util.Collection;
@@ -109,12 +123,7 @@ public static Object invoke(Map<String, Object> jsonMap, String function) throws
109123
public static Object invoke(String methodName, Class<?>[] parameterTypes, Object[] args) throws Exception {
110124
Function obj = new Function();
111125
Class<?> clazz = obj.getClass();
112-
// try {
113126
return clazz.getDeclaredMethod(methodName, parameterTypes).invoke(obj, args);
114-
// } catch (Exception e) {
115-
// e.printStackTrace();
116-
// }
117-
// return null;
118127
}
119128

120129

@@ -138,6 +147,7 @@ public String newVerify(String phone) {
138147
* @param collection
139148
* @return
140149
*/
150+
@Override
141151
public <T> boolean isEmpty(Collection<T> collection) {
142152
return BaseModel.isEmpty(collection);
143153
}
@@ -147,6 +157,7 @@ public <T> boolean isEmpty(Collection<T> collection) {
147157
* @param map
148158
* @return
149159
*/
160+
@Override
150161
public <K, V> boolean isEmpty(Map<K, V> map) {
151162
return BaseModel.isEmpty(map);
152163
}
@@ -158,6 +169,7 @@ public <K, V> boolean isEmpty(Map<K, V> map) {
158169
* @param object
159170
* @return
160171
*/
172+
@Override
161173
public <T> boolean isContain(Collection<T> collection, T object) {
162174
return BaseModel.isContain(collection, object);
163175
}
@@ -168,6 +180,7 @@ public <T> boolean isContain(Collection<T> collection, T object) {
168180
* @param key
169181
* @return
170182
*/
183+
@Override
171184
public <K, V> boolean isContainKey(Map<K, V> map, K key) {
172185
return BaseModel.isContainKey(map, key);
173186
}
@@ -178,6 +191,7 @@ public <K, V> boolean isContainKey(Map<K, V> map, K key) {
178191
* @param value
179192
* @return
180193
*/
194+
@Override
181195
public <K, V> boolean isContainValue(Map<K, V> map, V value) {
182196
return BaseModel.isContainValue(map, value);
183197
}
@@ -190,6 +204,7 @@ public <K, V> boolean isContainValue(Map<K, V> map, V value) {
190204
* @param array
191205
* @return
192206
*/
207+
@Override
193208
public <T> int count(T[] array) {
194209
return BaseModel.count(array);
195210
}
@@ -198,6 +213,7 @@ public <T> int count(T[] array) {
198213
* @param collection List, Vector, Set等都是Collection的子类
199214
* @return
200215
*/
216+
@Override
201217
public <T> int count(Collection<T> collection) {
202218
return BaseModel.count(collection);
203219
}
@@ -207,6 +223,7 @@ public <T> int count(Collection<T> collection) {
207223
* @param map
208224
* @return
209225
*/
226+
@Override
210227
public <K, V> int count(Map<K, V> map) {
211228
return BaseModel.count(map);
212229
}
@@ -219,6 +236,7 @@ public <K, V> int count(Map<K, V> map) {
219236
* @param array
220237
* @return
221238
*/
239+
@Override
222240
public <T> T get(T[] array, int position) {
223241
return BaseModel.get(array, position);
224242
}
@@ -227,6 +245,7 @@ public <T> T get(T[] array, int position) {
227245
* @param collection List, Vector, Set等都是Collection的子类
228246
* @return
229247
*/
248+
@Override
230249
public <T> T get(Collection<T> collection, int position) {
231250
return BaseModel.get(collection, position);
232251
}
@@ -237,6 +256,7 @@ public <T> T get(Collection<T> collection, int position) {
237256
* @param key null ? null : map.get(key);
238257
* @return
239258
*/
259+
@Override
240260
public <K, V> V get(Map<K, V> map, K key) {
241261
return BaseModel.get(map, key);
242262
}
@@ -249,34 +269,39 @@ public <K, V> V get(Map<K, V> map, K key) {
249269
* @param value
250270
* @return
251271
*/
272+
@Override
252273
public boolean value(Boolean value) {
253274
return BaseModel.value(value);
254275
}
255276
/**获取非空值
256277
* @param value
257278
* @return
258279
*/
280+
@Override
259281
public int value(Integer value) {
260282
return BaseModel.value(value);
261283
}
262284
/**获取非空值
263285
* @param value
264286
* @return
265287
*/
288+
@Override
266289
public long value(Long value) {
267290
return BaseModel.value(value);
268291
}
269292
/**获取非空值
270293
* @param value
271294
* @return
272295
*/
296+
@Override
273297
public float value(Float value) {
274298
return BaseModel.value(value);
275299
}
276300
/**获取非空值
277301
* @param value
278302
* @return
279303
*/
304+
@Override
280305
public double value(Double value) {
281306
return BaseModel.value(value);
282307
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
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+
115
package zuo.biao.apijson.server;
216

317
import zuo.biao.apijson.StringUtil;
418

19+
/**& | !逻辑类
20+
* @author Lemon
21+
*/
522
public class Logic {
623

724
public static final int TYPE_OR = 0;

0 commit comments

Comments
 (0)