Skip to content

Commit ceb2d5d

Browse files
committed
Server:JSONResponse新增getTotal;Client:与服务端同步公共类;初步测试获取total成功
1 parent e7827a1 commit ceb2d5d

File tree

5 files changed

+38
-15
lines changed

5 files changed

+38
-15
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,12 @@ public void onDialogButtonClick(int requestCode, boolean isPositive) {
501501
private final int HTTP_DELETE = 4;
502502
@Override
503503
public void onHttpResponse(int requestCode, String resultJson, Exception e) {
504+
if (requestCode <= 0) {
505+
// showShortToast("total=" + response.getTotal());
506+
super.onHttpResponse(requestCode, resultJson, e);
507+
return;
508+
}
509+
504510
JSONResponse response = new JSONResponse(resultJson);
505511
if (requestCode == HTTP_GET_MOMENT) {
506512
MomentItem data = JSONResponse.toObject(response, MomentItem.class);
@@ -516,10 +522,7 @@ public void onHttpResponse(int requestCode, String resultJson, Exception e) {
516522
setHead(data);
517523
return;
518524
}
519-
if (requestCode <= 0) {
520-
super.onHttpResponse(requestCode, resultJson, e);
521-
return;
522-
}
525+
523526

524527
JSONResponse comment = response.getJSONResponse(Comment.class.getSimpleName());
525528
boolean succeed = JSONResponse.isSucceed(comment);

APIJSON(Android)/APIJSON(ADT)/APIJSONApp/APIJSONApp/src/apijson/demo/client/util/HttpRequest.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -376,16 +376,6 @@ public static void getUserList(int range, long id, com.alibaba.fastjson.JSONObje
376376
* @param listener
377377
*/
378378
public static void getMoment(long id, int requestCode, OnHttpResponseListener listener) {
379-
380-
// //测试远程函数调用成功
381-
// JSONRequest request = new JSONRequest();
382-
// JSONRequest moment = new JSONRequest(KEY_ID, id);
383-
// // moment.put("praiseCount()", "count(Collection:praiseUserIdList)");//测试成功
384-
// // moment.put("praised()", "isContain(Collection:praiseUserIdList, userId)");//测试成功
385-
// // moment.put("plus()", "plus(long:id,long:userId)");//测试成功
386-
// // moment.put("@commentCount@", "Comment[]/total");
387-
// request.put(Moment.class.getSimpleName(), moment);
388-
389379
JSONRequest request = new JSONRequest(new Moment(id));
390380
request.put(User.class.getSimpleName(), new JSONRequest(ID_AT, "/Moment/userId"));
391381
//praise <<<<<<<<<<<<<<<<<<
@@ -462,7 +452,9 @@ public static void getMomentList(int range, long id, com.alibaba.fastjson.JSONOb
462452
commentItem.put(User.class.getSimpleName(), new JSONRequest(ID_AT, "/Comment/userId")
463453
.setColumn(COLUMNS_USER_SIMPLE));
464454

455+
465456
request.add(commentItem.toArray(10, 0, CommentItem.class.getSimpleName()));
457+
// request.put("commentCount@", "/CommentItem[]/total");
466458
//comment >>>>>>>>>>>>>>>>>>
467459

468460
get(request.toArray(count, page), requestCode, listener);
@@ -481,7 +473,10 @@ public static void getCommentList(long momentId, int count, int page
481473
JSONObject comment = new JSONObject(new Comment().setMomentId(momentId));
482474
request.put(Comment.class.getSimpleName(), comment.setOrder(DATE_UP));
483475
request.put(User.class.getSimpleName(), new JSONRequest(ID_AT, "/Comment/userId").setColumn(COLUMNS_USER));
484-
get(request.toArray(count, page), requestCode, listener);
476+
477+
request = request.toArray(count, page);
478+
// request.put("total@", "[]/total");
479+
get(request, requestCode, listener);
485480
}
486481

487482
/**赞动态

APIJSON(Android)/APIJSON(ADT)/APIJSONApp/APIJSONApp/src/apijson/demo/client/view/MomentView.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ public void bindView(MomentItem data_){
191191
vMomentViewDivider.setVisibility(llMomentViewPraise.getVisibility() == View.VISIBLE
192192
&& llMomentViewCommentContainer.getVisibility() == View.VISIBLE ? View.VISIBLE : View.GONE);
193193

194+
// tvMomentViewDate.setText(StringUtil.getTrimedString(tvMomentViewDate) + " total:" + data.getCommentCount());
194195
}
195196

196197

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public JSONResponse(JSONObject object) {
5353
public static final String KEY_ID = "id";
5454
public static final String KEY_STATUS = "status";
5555
public static final String KEY_COUNT = "count";
56+
public static final String KEY_TOTAL = "total";
5657
public static final String KEY_MESSAGE = "message";
5758

5859
/**获取id
@@ -73,6 +74,17 @@ public int getStatus() {
7374
public int getCount() {
7475
return getIntValue(KEY_COUNT);
7576
}
77+
/**获取数量
78+
* @return
79+
*/
80+
public int getTotal() {
81+
try {
82+
return getIntValue(KEY_TOTAL);
83+
} catch (Exception e) {
84+
// TODO: handle exception
85+
}
86+
return 0;
87+
}
7688
/**获取信息
7789
* @return
7890
*/

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public JSONResponse(JSONObject object) {
5353
public static final String KEY_ID = "id";
5454
public static final String KEY_STATUS = "status";
5555
public static final String KEY_COUNT = "count";
56+
public static final String KEY_TOTAL = "total";
5657
public static final String KEY_MESSAGE = "message";
5758

5859
/**获取id
@@ -73,6 +74,17 @@ public int getStatus() {
7374
public int getCount() {
7475
return getIntValue(KEY_COUNT);
7576
}
77+
/**获取数量
78+
* @return
79+
*/
80+
public int getTotal() {
81+
try {
82+
return getIntValue(KEY_TOTAL);
83+
} catch (Exception e) {
84+
// TODO: handle exception
85+
}
86+
return 0;
87+
}
7688
/**获取信息
7789
* @return
7890
*/

0 commit comments

Comments
 (0)