Skip to content

Commit 74085ad

Browse files
committed
Model内基本类型改为对应的Object类型
1 parent 61719ca commit 74085ad

6 files changed

Lines changed: 45 additions & 131 deletions

File tree

APIJSON(Android)/APIJSON(ADT)/src/zuo/biao/apijson/JSONObject.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,5 @@ public JSONObject() {
2424
super(true);
2525
}
2626

27-
// public Object put(Field key, Object value) {
28-
// return put(key.getName(), value);
29-
// }
3027

3128
}

APIJSON(Android)/APIJSON(ADT)/src/zuo/biao/apijson/client/RequestUtil2.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
public class RequestUtil2 {
3131

3232

33-
// private static final String SEPRATOR = "/";
34-
3533
/**
3634
* @param object
3735
* @return
@@ -111,7 +109,7 @@ public static JSONObject newSingleRequest() {
111109
public static JSONObject newRelyRequest() {
112110
JSONObject object = new JSONObject();
113111

114-
object.put(User.TAG, new User((long) 38710));
112+
object.put(User.class.getSimpleName(), new User((long) 38710));
115113

116114
JSONObject workObject = new JSONObject();
117115
try {
@@ -120,7 +118,7 @@ public static JSONObject newRelyRequest() {
120118
e.printStackTrace();
121119
return null;
122120
}
123-
object.put(Work.TAG, workObject);
121+
object.put(Work.class.getSimpleName(), workObject);
124122

125123
return object;
126124
}

APIJSON(Android)/APIJSON(ADT)/src/zuo/biao/apijson/client/model/BaseModel.java

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,17 @@
1616

1717
import java.io.Serializable;
1818

19-
import zuo.biao.apijson.JSON;
20-
21-
import com.alibaba.fastjson.JSONObject;
22-
2319
/**基础Model
2420
* *isCorrect可以用于BaseModel子类的数据校验
2521
* *implements Serializable 是为了网络传输字节流转换
2622
* @author Lemon
2723
* @use extends BaseModel
2824
*/
2925
public abstract class BaseModel implements Serializable {
30-
private static final String TAG = "BaseModel";
31-
32-
/**
33-
* default, 怎么设置子类都有warning
34-
*/
35-
private static final long serialVersionUID = 1L;
36-
37-
38-
26+
private static final long serialVersionUID = 7560533944342381808L;
3927

4028
public Long id;
4129

42-
4330
public Long getId() {
4431
return id;
4532
}
@@ -61,54 +48,4 @@ public void setId(Long id) {
6148
// */
6249
// public abstract boolean isCorrect();
6350

64-
/**把这个类的实例转为JSONObject
65-
* @return
66-
*/
67-
public JSONObject toJSONObject() {
68-
return toJSONObject(this);
69-
}
70-
/**通过反射把这个类的实例转为JSONObject<变量类型名, 变量值>
71-
* @param <T> 类型
72-
* @param object 实现类
73-
* @return
74-
*/
75-
public <T> JSONObject toJSONObject(T object) {
76-
return object == null ? null : JSON.parseObject(object.toString());
77-
78-
// ObjectRequest jsonObject = new ObjectRequest(true);
79-
//
80-
// Field[] fields = object == null ? null : object.getClass().getDeclaredFields();
81-
// if (fields != null) {
82-
// Object value;
83-
// for (Field field : fields) {
84-
// field.setAccessible(true);
85-
// try {
86-
// value = field.get(object);
87-
// if (value != null) {
88-
// jsonObject.put(field.getName(), field.get(object));
89-
// }
90-
// } catch (IllegalAccessException e) {
91-
// e.printStackTrace();
92-
// } catch (IllegalArgumentException e) {
93-
// e.printStackTrace();
94-
// }
95-
// }
96-
// }
97-
//
98-
// return jsonObject;
99-
}
100-
101-
@Override
102-
public String toString() {
103-
return JSON.toJSONString(this);
104-
}
105-
106-
public static String getFieldPath(String fieldName) {
107-
return fieldName == null ? null : TAG + "/" + fieldName;
108-
}
109-
110-
// public void getFieldName(Object object) {
111-
// Field field = Field.DECLARED;
112-
//return object.get
113-
// }
11451
}
Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,64 @@
1-
package zuo.biao.apijson.client.model;
1+
/*Copyright ©2015 TommyLemon(https://github.com/TommyLemon)
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
26
3-
public class Comment {
7+
http://www.apache.org/licenses/LICENSE-2.0
48
5-
long id;
6-
long workId;
7-
long parentId;
8-
long userId;
9-
long targetUserId;
10-
String userName;
11-
String targetUserName;
12-
String content;
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.client.model;
16+
17+
/**评论类
18+
* @author Lemon
19+
*/
20+
public class Comment extends BaseModel {
21+
private static final long serialVersionUID = -1011007127735372824L;
22+
23+
24+
public Long workId;
25+
public Long parentId;
26+
public Long userId;
27+
public Long targetUserId;
28+
public String userName;
29+
public String targetUserName;
30+
public String content;
1331
public Comment() {
14-
// TODO Auto-generated constructor stub
32+
super();
1533
}
16-
public Comment(long id, String content) {
34+
public Comment(Long id, String content) {
1735
this();
1836
this.id = id;
1937
this.content = content;
2038
}
21-
public long getId() {
22-
return id;
23-
}
24-
public void setId(long id) {
25-
this.id = id;
26-
}
27-
public long getWorkId() {
39+
40+
public Long getWorkId() {
2841
return workId;
2942
}
30-
public void setWorkId(long workId) {
43+
public void setWorkId(Long workId) {
3144
this.workId = workId;
3245
}
33-
public long getParentId() {
46+
public Long getParentId() {
3447
return parentId;
3548
}
36-
public void setParentId(long parentId) {
49+
public void setParentId(Long parentId) {
3750
this.parentId = parentId;
3851
}
39-
public long getUserId() {
52+
public Long getUserId() {
4053
return userId;
4154
}
42-
public void setUserId(long userId) {
55+
public void setUserId(Long userId) {
4356
this.userId = userId;
4457
}
45-
public long getTargetUserId() {
58+
public Long getTargetUserId() {
4659
return targetUserId;
4760
}
48-
public void setTargetUserId(long targetUserId) {
61+
public void setTargetUserId(Long targetUserId) {
4962
this.targetUserId = targetUserId;
5063
}
5164
public String getUserName() {
@@ -68,6 +81,4 @@ public void setContent(String content) {
6881
}
6982

7083

71-
72-
7384
}

APIJSON(Android)/APIJSON(ADT)/src/zuo/biao/apijson/client/model/User.java

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

1515
package zuo.biao.apijson.client.model;
1616

17-
18-
1917
/**用户类
2018
* @author Lemon
2119
*/
22-
public class User {//extends BaseModel {
23-
public static final String TAG = "User";
24-
25-
// private static final long serialVersionUID = 1L;
26-
27-
public Long id;
20+
public class User extends BaseModel {
21+
private static final long serialVersionUID = -1635551656020732611L;
22+
2823
public Integer sex;
2924
public String head;
3025
public String name;
@@ -45,13 +40,6 @@ public User(Long id, String name) {
4540
this.name = name;
4641
}
4742

48-
public Long getId() {
49-
return id;
50-
}
51-
public User setId(Long id) {
52-
this.id = id;
53-
return this;
54-
}
5543
public Integer getSex() {
5644
return sex;
5745
}

APIJSON(Android)/APIJSON(ADT)/src/zuo/biao/apijson/client/model/Work.java

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

1515
package zuo.biao.apijson.client.model;
1616

17-
18-
import com.alibaba.fastjson.JSON;
19-
import com.alibaba.fastjson.JSONObject;
20-
2117
/**作品类,名字对应服务器数据库的table_name,变量名及其类型和table里的column一一对应
2218
* @author Lemon
2319
*/
2420
public class Work extends BaseModel {
25-
public static final String TAG = "Work";
26-
2721
private static final long serialVersionUID = -7437225320551780084L;
2822

29-
3023
public long userId;
3124
public String title;
3225
public String content;
@@ -73,14 +66,4 @@ public void setPicture(String picture) {
7366
// && (StringUtil.isNotEmpty(getTitle(), true) || StringUtil.isNotEmpty(getContent(), true));
7467
// }
7568

76-
@Override
77-
public JSONObject toJSONObject() {
78-
return toJSONObject(this);
79-
}
80-
81-
@Override
82-
public String toString() {
83-
return JSON.toJSONString(this);
84-
}
85-
8669
}

0 commit comments

Comments
 (0)