Skip to content

Commit f76d950

Browse files
committed
Client:避免put(Object object)传入Server没有对应model的object;与server同步model
1 parent 549685d commit f76d950

9 files changed

Lines changed: 64 additions & 81 deletions

File tree

APIJSON(Android)/APIJSON(ADT)/APIJSONApp/APIJSONApp/src/apijson/demo/client/server/model/Comment.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,16 @@
1414

1515
package apijson.demo.client.server.model;
1616

17+
import zuo.biao.apijson.APIJSONRequest;
18+
import zuo.biao.apijson.RequestMethod;
19+
1720
/**评论类
1821
* @author Lemon
1922
*/
23+
@APIJSONRequest(
24+
method = {RequestMethod.GET, RequestMethod.HEAD, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE},
25+
DELETE = "{necessaryColumns:id}"
26+
)
2027
public class Comment extends BaseModel {
2128
private static final long serialVersionUID = -1011007127735372824L;
2229

APIJSON(Android)/APIJSON(ADT)/APIJSONApp/APIJSONApp/src/apijson/demo/client/server/model/Login.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,17 @@
1414

1515
package apijson.demo.client.server.model;
1616

17+
import zuo.biao.apijson.APIJSONRequest;
18+
import zuo.biao.apijson.RequestMethod;
19+
1720
/**登录类
1821
* @author Lemon
1922
*/
2023
@SuppressWarnings("serial")
24+
@APIJSONRequest(
25+
method = {RequestMethod.POST_GET, RequestMethod.POST, RequestMethod.DELETE},
26+
DELETE = "{necessaryColumns:id}"
27+
)
2128
public class Login extends BaseModel {
2229

2330
public static final int TYPE_PASSWORD = 0;

APIJSON(Android)/APIJSON(ADT)/APIJSONApp/APIJSONApp/src/apijson/demo/client/server/model/Moment.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,16 @@
1616

1717
import java.util.List;
1818

19+
import zuo.biao.apijson.APIJSONRequest;
20+
import zuo.biao.apijson.RequestMethod;
21+
1922
/**作品类
2023
* @author Lemon
2124
*/
25+
@APIJSONRequest(
26+
method = {RequestMethod.GET, RequestMethod.HEAD, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE},
27+
DELETE = "{necessaryColumns:id}"
28+
)
2229
public class Moment extends BaseModel {
2330
private static final long serialVersionUID = -7437225320551780084L;
2431

APIJSON(Android)/APIJSON(ADT)/APIJSONApp/APIJSONApp/src/apijson/demo/client/server/model/Password.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,18 @@
1414

1515
package apijson.demo.client.server.model;
1616

17+
import zuo.biao.apijson.APIJSONRequest;
18+
import zuo.biao.apijson.RequestMethod;
1719
import zuo.biao.apijson.StringUtil;
1820

1921
/**登录类
2022
* @author Lemon
2123
*/
2224
@SuppressWarnings("serial")
25+
@APIJSONRequest(
26+
method = {RequestMethod.POST_GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE},
27+
DELETE = "{necessaryColumns:id}"
28+
)
2329
public class Password extends BaseModel {
2430

2531
private String model;//table是MySQL关键字不能用!
@@ -32,15 +38,20 @@ public Password() {
3238
public Password(String model, String phone) {
3339
this();
3440
setModel(model);
35-
setId(Long.valueOf(0 + StringUtil.getNumber(phone)));
41+
setPhone(phone);
3642
}
37-
public Password(String model, String phone, String value) {
43+
public Password(String model, String phone, String password) {
3844
this(model, phone);
39-
setPassword(value);
45+
setPassword(password);
4046
}
4147

48+
public Password setPhone(String phone) {
49+
setId(Long.valueOf(0 + StringUtil.getNumber(phone)));
50+
return this;
51+
}
52+
4253
public String getModel() {
43-
return model;
54+
return StringUtil.isNotEmpty(model, true) ? model : "User";
4455
}
4556
public Password setModel(String model) {
4657
this.model = model;

APIJSON(Android)/APIJSON(ADT)/APIJSONApp/APIJSONApp/src/apijson/demo/client/server/model/Request.java

Lines changed: 0 additions & 71 deletions
This file was deleted.

APIJSON(Android)/APIJSON(ADT)/APIJSONApp/APIJSONApp/src/apijson/demo/client/server/model/Verify.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,18 @@
1414

1515
package apijson.demo.client.server.model;
1616

17+
import zuo.biao.apijson.APIJSONRequest;
18+
import zuo.biao.apijson.RequestMethod;
1719
import zuo.biao.apijson.StringUtil;
1820

1921
/**登录类
2022
* @author Lemon
2123
*/
2224
@SuppressWarnings("serial")
25+
@APIJSONRequest(
26+
method = {RequestMethod.POST_HEAD, RequestMethod.POST_GET, RequestMethod.POST, RequestMethod.DELETE},
27+
DELETE = "{necessaryColumns:id}"
28+
)
2329
public class Verify extends BaseModel {
2430

2531
private String code;

APIJSON(Android)/APIJSON(ADT)/APIJSONApp/APIJSONApp/src/apijson/demo/client/server/model/Wallet.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,17 @@
1616

1717
import java.math.BigDecimal;
1818

19+
import zuo.biao.apijson.APIJSONRequest;
20+
import zuo.biao.apijson.RequestMethod;
21+
1922
/**钱包类
2023
* @author Lemon
2124
*/
25+
@APIJSONRequest(
26+
method = {RequestMethod.POST_GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE},
27+
POST_GET = "{Wallet:{disallowColumns:!, necessaryColumns:userId}, necessaryColumns:currentUserId,loginPassword}",
28+
DELETE = "{necessaryColumns:id}"
29+
)
2230
public class Wallet extends BaseModel {
2331
private static final long serialVersionUID = 4298571449155754300L;
2432

APIJSON(Android)/APIJSON(ADT)/APIJSONLibrary/src/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(Android)/APIJSON(ADT)/APIJSONLibrary/src/zuo/biao/apijson/JSONRequest.java

Lines changed: 4 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
*/
@@ -133,9 +133,10 @@ public Object putPath(String key, String... parts) {
133133

134134
/**
135135
* encode = true
136-
* @param value
136+
* @param value must be annotated by {@link APIJSONRequest}
137137
* @return {@link #put(String, boolean)}
138138
*/
139+
@Override
139140
public Object put(Object value) {
140141
return put(value, true);
141142
}

0 commit comments

Comments
 (0)