Skip to content

Commit a7d8997

Browse files
committed
Server:同步eclipse版至idea版;Client:优化注册时验证码错误提示
1 parent 7e02612 commit a7d8997

File tree

24 files changed

+692
-124
lines changed

24 files changed

+692
-124
lines changed

APIJSON(Android)/APIJSON(ADT)/APIJSONApp/APIJSONApp/src/apijson/demo/client/activity_fragment/PasswordActivity.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,12 @@ public void run() {
397397
dismissProgress();
398398
if (user == null || user.getId() <= 0 || JSONResponse.isSucceed(
399399
response.getJSONResponse(User.class.getSimpleName())) == false) {
400-
showShortToast("注册失败,请检查网络后重试");
401-
return;
400+
if (response.getStatus() == 408 || response.getStatus() == 412) {
401+
EditTextManager.showInputedError(context, etPasswordVerify
402+
, response.getStatus() == 408 ? "验证码已过期" : "验证码错误");
403+
} else {
404+
showShortToast("注册失败,请检查网络后重试");
405+
}
402406
} else {
403407
showShortToast("注册成功");
404408
APIJSONApplication.getInstance().saveCurrentUser(user);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,13 @@ public String register(@RequestBody String request) {
249249
// , new IllegalArgumentException("User.verify: " + verify + " 不合法!不能小于6个字符!")));
250250
// }
251251

252-
JSONResponse response = new JSONResponse(checkVerify(phone, user.getString("verify")));
252+
JSONResponse response = new JSONResponse(checkVerify(phone, requestObject.getString("verify")));
253253
if (JSONResponse.isSucceed(response) == false) {
254254
return JSON.toJSONString(response);
255255
}
256256
//手机号或验证码错误
257257
if (JSONResponse.isExist(response.getJSONResponse(Verify.class.getSimpleName())) == false) {
258-
return JSON.toJSONString(RequestParser.extendErrorResult(requestObject
258+
return JSON.toJSONString(RequestParser.extendErrorResult(response
259259
, new ConditionNotMatchException("手机号或验证码错误!")));
260260
}
261261

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* 示例服务端工程包
3+
*/
4+
/**
5+
* @author Lemon
6+
*
7+
*/
8+
package apijson.demo.server;
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
import java.lang.annotation.Documented;
18+
import java.lang.annotation.ElementType;
19+
import java.lang.annotation.Retention;
20+
import java.lang.annotation.RetentionPolicy;
21+
import java.lang.annotation.Target;
22+
23+
/**请求方法对应的JSON结构
24+
* @author Lemon
25+
*/
26+
@Target({ElementType.METHOD, ElementType.TYPE})
27+
@Retention(RetentionPolicy.RUNTIME)
28+
@Documented
29+
public @interface APIJSONRequest {
30+
31+
/**
32+
* @return 允许的请求方法
33+
*/
34+
RequestMethod[] method() default {};
35+
36+
37+
/**@see {@link RequestMethod#POST_GET}
38+
* @return 该请求方法允许的结构
39+
*/
40+
String POST_GET() default "";
41+
42+
/**@see {@link RequestMethod#POST_HEAD}
43+
* @return 该请求方法允许的结构
44+
*/
45+
String POST_HEAD() default "";
46+
47+
/**@see {@link RequestMethod#POST}
48+
* @return 该请求方法允许的结构
49+
*/
50+
String POST() default "";
51+
52+
/**@see {@link RequestMethod#PUT}
53+
* @return 该请求方法允许的结构
54+
*/
55+
String PUT() default "";
56+
57+
/**@see {@link RequestMethod#DELETE}
58+
* @return 该请求方法允许的结构
59+
*/
60+
String DELETE() default "";
61+
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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+
import java.util.Collection;
18+
import java.util.Map;
19+
20+
/**可远程调用的函数列表
21+
* @author Lemon
22+
*/
23+
public interface FunctionList {
24+
25+
//判断是否为空 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
26+
/**判断collection是否为空
27+
* @param collection
28+
* @return
29+
*/
30+
public <T> boolean isEmpty(Collection<T> collection);
31+
/**判断map是否为空
32+
* @param <K>
33+
* @param <V>
34+
* @param map
35+
* @return
36+
*/
37+
public <K, V> boolean isEmpty(Map<K, V> map);
38+
//判断是否为空 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
39+
40+
//判断是否为包含 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
41+
/**判断collection是否包含object
42+
* @param collection
43+
* @param object
44+
* @return
45+
*/
46+
public <T> boolean isContain(Collection<T> collection, T object);
47+
/**判断map是否包含key
48+
* @param <K>
49+
* @param <V>
50+
* @param map
51+
* @param key
52+
* @return
53+
*/
54+
public <K, V> boolean isContainKey(Map<K, V> map, K key);
55+
/**判断map是否包含value
56+
* @param <K>
57+
* @param <V>
58+
* @param map
59+
* @param value
60+
* @return
61+
*/
62+
public <K, V> boolean isContainValue(Map<K, V> map, V value);
63+
//判断是否为包含 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
64+
65+
66+
//获取集合长度 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
67+
/**获取数量
68+
* @param <T>
69+
* @param array
70+
* @return
71+
*/
72+
public <T> int count(T[] array);
73+
/**获取数量
74+
* @param <T>
75+
* @param collection List, Vector, Set等都是Collection的子类
76+
* @return
77+
*/
78+
public <T> int count(Collection<T> collection);
79+
/**获取数量
80+
* @param <K>
81+
* @param <V>
82+
* @param map
83+
* @return
84+
*/
85+
public <K, V> int count(Map<K, V> map);
86+
//获取集合长度 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
87+
88+
89+
//获取集合长度 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
90+
/**获取
91+
* @param <T>
92+
* @param array
93+
* @return
94+
*/
95+
public <T> T get(T[] array, int position);
96+
/**获取
97+
* @param <T>
98+
* @param collection List, Vector, Set等都是Collection的子类
99+
* @return
100+
*/
101+
public <T> T get(Collection<T> collection, int position);
102+
/**获取
103+
* @param <K>
104+
* @param <V>
105+
* @param map null ? null
106+
* @param key null ? null : map.get(key);
107+
* @return
108+
*/
109+
public <K, V> V get(Map<K, V> map, K key);
110+
//获取集合长度 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
111+
112+
113+
114+
//获取非基本类型对应基本类型的非空值 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
115+
/**获取非空值
116+
* @param value
117+
* @return
118+
*/
119+
public boolean value(Boolean value);
120+
/**获取非空值
121+
* @param value
122+
* @return
123+
*/
124+
public int value(Integer value);
125+
/**获取非空值
126+
* @param value
127+
* @return
128+
*/
129+
public long value(Long value);
130+
/**获取非空值
131+
* @param value
132+
* @return
133+
*/
134+
public float value(Float value);
135+
/**获取非空值
136+
* @param value
137+
* @return
138+
*/
139+
public double value(Double value);
140+
//获取非基本类型对应基本类型的非空值 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
141+
142+
}

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,15 @@ public Object get(Object key, boolean decode) {
145145

146146
/**
147147
* encode = false
148-
* @param value
148+
* @param value must be annotated by {@link APIJSONRequest}
149149
* @return {@link #put(String, boolean)}
150150
*/
151151
public Object put(Object value) {
152152
return put(value, false);
153153
}
154154
/**
155155
* key = value.getClass().getSimpleName()
156-
* @param value
156+
* @param value must be annotated by {@link APIJSONRequest}
157157
* @param encode
158158
* @return {@link #put(String, Object, boolean)}
159159
*/
@@ -170,7 +170,14 @@ public Object put(Object value, boolean encode) {
170170
*/
171171
public Object put(String key, Object value, boolean encode) {
172172
if (StringUtil.isNotEmpty(key, true) == false) {
173-
key = value == null ? null : value.getClass().getSimpleName();
173+
Class<?> clazz = value == null ? null : value.getClass();
174+
if (clazz == null || clazz.getAnnotation(APIJSONRequest.class) == null) {
175+
throw new IllegalArgumentException("put StringUtil.isNotEmpty(key, true) == false" +
176+
" && clazz == null || clazz.getAnnotation(APIJSONRequest.class) == null" +
177+
" \n key为空时仅支持 类型被@APIJSONRequest注解 的value !!!" +
178+
" \n 如果一定要这么用,请对 " + clazz.getName() + " 注解!");
179+
}
180+
key = value.getClass().getSimpleName();
174181
}
175182
if (encode) {
176183
if (key.endsWith("+") || key.endsWith("-")) {

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public JSONRequest() {
3030
}
3131
/**
3232
* encode = true
33-
* @param object
33+
* @param object must be annotated by {@link APIJSONRequest}
3434
* @see {@link #JSONRequest(String, Object)}
3535
*/
3636
public JSONRequest(Object object) {
@@ -46,7 +46,7 @@ public JSONRequest(String name, Object object) {
4646
this(name, object, true);
4747
}
4848
/**
49-
* @param object
49+
* @param object must be annotated by {@link APIJSONRequest}
5050
* @param encode
5151
* @see {@link #JSONRequest(String, Object, boolean)}
5252
*/
@@ -84,6 +84,7 @@ public String getTag() {
8484

8585
public static final String KEY_COUNT = "count";
8686
public static final String KEY_PAGE = "page";
87+
public static final String KEY_TOTAL = "total";
8788

8889
public JSONRequest setCount(int count) {
8990
put(KEY_COUNT, count);
@@ -100,6 +101,15 @@ public JSONRequest setPage(int page) {
100101
public int getPage() {
101102
return getIntValue(KEY_PAGE);
102103
}
104+
// private int total;
105+
public JSONRequest setTotal(int total) {
106+
// this.total = total;
107+
put(KEY_TOTAL, total);
108+
return this;
109+
}
110+
public int getTotal() {
111+
return getIntValue(KEY_TOTAL);//total;//
112+
}
103113
//array object >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
104114

105115

@@ -133,9 +143,10 @@ public Object putPath(String key, String... parts) {
133143

134144
/**
135145
* encode = true
136-
* @param value
146+
* @param value must be annotated by {@link APIJSONRequest}
137147
* @return {@link #put(String, boolean)}
138148
*/
149+
@Override
139150
public Object put(Object value) {
140151
return put(value, true);
141152
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class TypeValueKeyEntry extends Entry<String, String> {
2525

2626
private static Map<String, Class<?>> classMap;
2727
static {
28-
classMap = new HashMap<>();
28+
classMap = new HashMap<String, Class<?>>();
2929
classMap.put(boolean.class.getSimpleName(), boolean.class);
3030
classMap.put(int.class.getSimpleName(), int.class);
3131
classMap.put(long.class.getSimpleName(), long.class);
@@ -110,7 +110,7 @@ public static Entry<Class<?>, Object> parseEntry(Map<String, Object> valueMap, S
110110
}
111111
int index = typeValue.contains(":") ? typeValue.indexOf(":") : -1;
112112

113-
Entry<Class<?>, Object> entry = new Entry<>();
113+
Entry<Class<?>, Object> entry = new Entry<Class<?>, Object>();
114114
entry.setKey(classMap.get(index < 0 ? Object.class.getSimpleName() : typeValue.substring(0, index)));
115115
entry.setValue(valueMap == null ? null : valueMap.get(typeValue.substring(index + 1, typeValue.length())));
116116

0 commit comments

Comments
 (0)