Skip to content

Commit 15e21f2

Browse files
committed
Server:新增page分页;解决无条件不能获取全部;解决count<=0导致没有查询结果;Client:优化测试示例
1 parent d5046a7 commit 15e21f2

File tree

9 files changed

+46
-40
lines changed

9 files changed

+46
-40
lines changed

APIJSON(Android)/APIJSON(ADT)/APIJSONDemoApp/res/values-zh/strings.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,5 @@
1313
<string name="access_permitted">允许使用权限</string>
1414
<string name="query">查询</string>
1515
<string name="query_error">可能出现了一些问题,可以按照以下步骤解决:\n\n1.检查网络连接\n\n2.检查url是否为一个可用的IPV4地址\n\n3.长按[查询]按钮用浏览器发送请求\n\n4.查看目标服务器上的log\n\n5.再试一次</string>
16-
<string name="demo_single">{\n&#160;&#160;&#160;\"User\":{\n&#160;&#160;&#160;&#160;&#160;&#160;\"id\":38710\n&#160;&#160;&#160;}\n}</string>
17-
<string name="demo_rely">{\n&#160;&#160;&#160;\"User\":{\n&#160;&#160;&#160;&#160;&#160;&#160;\"id\":70793\n&#160;&#160;&#160;},\n&#160;&#160;&#160;\"Work\":{\n&#160;&#160;&#160;&#160;&#160;&#160;\"userId\":\"User/id\"\n&#160;&#160;&#160;}\n}</string>
18-
<string name="demo_array">{\n&#160;&#160;&#160;\"User[]\":{\n&#160;&#160;&#160;&#160;&#160;&#160;\"count\":10,\n&#160;&#160;&#160;&#160;&#160;&#160;\"User\":{\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;\"sex\":0\n&#160;&#160;&#160;&#160;&#160;&#160;}\n&#160;&#160;&#160;}\n}</string>
19-
<string name="demo_complex">{\n&#160;&#160;&#160;\"[]\":{\n&#160;&#160;&#160;&#160;&#160;&#160;\"count\":2,\n&#160;&#160;&#160;&#160;&#160;&#160;\"User\":{\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;\"sex\":0\n&#160;&#160;&#160;&#160;&#160;&#160;},\n&#160;&#160;&#160;&#160;&#160;&#160;\"Work\":{\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;\"userId\":\"/User/id\"\n&#160;&#160;&#160;&#160;&#160;&#160;},\n&#160;&#160;&#160;&#160;&#160;&#160;\"Comment[]\":{\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;\"count\":3,\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;\"Comment\":{\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;\"workId\":\"[]/Work/id\"\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}\n&#160;&#160;&#160;&#160;&#160;&#160;}\n&#160;&#160;&#160;}\n}</string>
20-
<string name="demo_wallet">{\n&#160;&#160;&#160;\"Wallet\":{\n&#160;&#160;&#160;&#160;&#160;&#160;\"userId\":38710\n&#160;&#160;&#160;}\n}</string>
21-
<string name="demo_wallet_with_access">{\n&#160;&#160;&#160;\"Wallet\":{\n&#160;&#160;&#160;&#160;&#160;&#160;\"userId\":38710\n&#160;&#160;&#160;},\n&#160;&#160;&#160;\"currentUserId\":38710,\n&#160;&#160;&#160;\"payPassword\":\"123456\"\n}</string>
2216

2317
</resources>

APIJSON(Android)/APIJSON(ADT)/APIJSONDemoApp/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<string name="query_error">There may be something wrong,you can follow by the steps:\n\n1.Check your net connection\n\n2.Check the url whether it\'s an available ipv4 address\n\n3.Long click the [Query] button to open the request by web browser\n\n4.Check logs outputed on the target server\n\n5.Try again</string>
1616
<string name="demo_single">{\n&#160;&#160;&#160;\"User\":{\n&#160;&#160;&#160;&#160;&#160;&#160;\"id\":38710\n&#160;&#160;&#160;}\n}</string>
1717
<string name="demo_rely">{\n&#160;&#160;&#160;\"User\":{\n&#160;&#160;&#160;&#160;&#160;&#160;\"id\":70793\n&#160;&#160;&#160;},\n&#160;&#160;&#160;\"Work\":{\n&#160;&#160;&#160;&#160;&#160;&#160;\"userId\":\"User/id\"\n&#160;&#160;&#160;}\n}</string>
18-
<string name="demo_array">{\n&#160;&#160;&#160;\"User[]\":{\n&#160;&#160;&#160;&#160;&#160;&#160;\"count\":10,\n&#160;&#160;&#160;&#160;&#160;&#160;\"User\":{\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;\"sex\":0\n&#160;&#160;&#160;&#160;&#160;&#160;}\n&#160;&#160;&#160;}\n}</string>
18+
<string name="demo_array">{\n&#160;&#160;&#160;\"User[]\":{\n&#160;&#160;&#160;&#160;&#160;&#160;\"count\":5,\n&#160;&#160;&#160;&#160;&#160;&#160;\"page\":1,\n&#160;&#160;&#160;&#160;&#160;&#160;\"User\":{\n&#160;&#160;&#160;&#160;&#160;&#160;}\n&#160;&#160;&#160;}\n}</string>
1919
<string name="demo_complex">{\n&#160;&#160;&#160;\"[]\":{\n&#160;&#160;&#160;&#160;&#160;&#160;\"count\":2,\n&#160;&#160;&#160;&#160;&#160;&#160;\"User\":{\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;\"sex\":0\n&#160;&#160;&#160;&#160;&#160;&#160;},\n&#160;&#160;&#160;&#160;&#160;&#160;\"Work\":{\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;\"userId\":\"/User/id\"\n&#160;&#160;&#160;&#160;&#160;&#160;},\n&#160;&#160;&#160;&#160;&#160;&#160;\"Comment[]\":{\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;\"count\":3,\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;\"Comment\":{\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;\"workId\":\"[]/Work/id\"\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}\n&#160;&#160;&#160;&#160;&#160;&#160;}\n&#160;&#160;&#160;}\n}</string>
2020
<string name="demo_wallet">{\n&#160;&#160;&#160;\"Wallet\":{\n&#160;&#160;&#160;&#160;&#160;&#160;\"userId\":38710\n&#160;&#160;&#160;}\n}</string>
2121
<string name="demo_wallet_with_access">{\n&#160;&#160;&#160;\"Wallet\":{\n&#160;&#160;&#160;&#160;&#160;&#160;\"userId\":38710\n&#160;&#160;&#160;},\n&#160;&#160;&#160;\"currentUserId\":38710,\n&#160;&#160;&#160;\"payPassword\":\"123456\"\n}</string>

APIJSON(Android)/APIJSON(ADT)/APIJSONDemoApp/src/apijson/demo/RequestUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static JSONObject newRelyRequest() {
3838
}
3939

4040
public static JSONObject newArrayRequest() {
41-
return new JSONRequest(new User().setSex(0)).toArray(10, 0, User.class.getSimpleName());
41+
return new JSONRequest(new User()).toArray(5, 1, User.class.getSimpleName());
4242
}
4343

4444
public static JSONObject newComplexRequest() {
@@ -50,7 +50,7 @@ public static JSONObject newComplexRequest() {
5050
request.add(new JSONRequest(Comment.class.getSimpleName(), new JSONRequest("workId", "[]/Work/id")).
5151
toArray(3, 0, Comment.class.getSimpleName()));
5252

53-
return request.toArray(2, 1);
53+
return request.toArray(2, 0);
5454
}
5555

5656
public static JSONObject newAccessErrorRequest() {

APIJSON(Android)/APIJSON(ADT)/APIJSONDemoApp/src/apijson/demo/ui/SelectActivity.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,52 +28,52 @@
2828
public class SelectActivity extends Activity {
2929

3030
public static final String RESULT_JSON = "RESULT_JSON";
31-
31+
3232
public static Intent createIntent(Context context) {
3333
return new Intent(context, SelectActivity.class);
3434
}
35-
36-
35+
36+
3737
private Activity context;
3838
@Override
3939
protected void onCreate(Bundle savedInstanceState) {
4040
super.onCreate(savedInstanceState);
4141
setContentView(R.layout.select_activity);
42-
42+
4343
context = this;
4444
}
4545

4646
//click event,called form layout android:onClick <<<<<<<<<<<<<<<<
4747
public void selectSingle(View v) {
4848
select(QueryActivity.TYPE_SINGLE);
4949
}
50-
50+
5151
public void selectRely(View v) {
5252
select(QueryActivity.TYPE_RELY);
5353
}
54-
54+
5555
public void selectArray(View v) {
5656
select(QueryActivity.TYPE_ARRAY);
5757
}
58-
58+
5959
public void selectComplex(View v) {
6060
select(QueryActivity.TYPE_COMPLEX);
6161
}
62-
62+
6363
public void selectAccessError(View v) {
6464
select(QueryActivity.TYPE_ACCESS_ERROR);
6565
}
66-
66+
6767
public void selectAccessPermitted(View v) {
6868
select(QueryActivity.TYPE_ACCESS_PERMITTED);
6969
}
7070
//click event,called form layout android:onClick >>>>>>>>>>>>>>>>
71-
71+
7272
private String url;
7373
private void select(int type) {
7474
startActivityForResult(QueryActivity.createIntent(context, type, url), REQUEST_TO_QUERY);
7575
}
76-
76+
7777
private static final int REQUEST_TO_QUERY = 1;
7878
@Override
7979
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
@@ -85,14 +85,14 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
8585
case REQUEST_TO_QUERY:
8686
if (data == null) {
8787
Toast.makeText(context, "onActivityResult data == null !!!", Toast.LENGTH_SHORT).show();
88-
return;
88+
} else {
89+
url = data.getStringExtra(QueryActivity.RESULT_URL);
8990
}
90-
url = data.getStringExtra(QueryActivity.RESULT_URL);
9191
break;
9292
default:
9393
break;
9494
}
9595
}
9696

97-
97+
9898
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@ public class JSON {
3333
*/
3434
public static boolean isJsonCorrect(String s) {
3535
System.out.println(TAG + "isJsonCorrect <<<< " + s + " >>>>>>>");
36-
if (s == null || s.equals("[]")
37-
|| s.equals("{}") || s.equals("") || s.equals("[null]") || s.equals("{null}") || s.equals("null")) {
36+
if (s == null
37+
// || s.equals("[]")
38+
// || s.equals("{}")
39+
|| s.equals("")
40+
|| s.equals("[null]")
41+
|| s.equals("{null}")
42+
|| s.equals("null")) {
3843
return false;
3944
}
4045
return true;

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@ public class JSON {
3333
*/
3434
public static boolean isJsonCorrect(String s) {
3535
System.out.println(TAG + "isJsonCorrect <<<< " + s + " >>>>>>>");
36-
if (s == null || s.equals("[]")
37-
|| s.equals("{}") || s.equals("") || s.equals("[null]") || s.equals("{null}") || s.equals("null")) {
36+
if (s == null
37+
// || s.equals("[]")
38+
// || s.equals("{}")
39+
|| s.equals("")
40+
|| s.equals("[null]")
41+
|| s.equals("{null}")
42+
|| s.equals("null")) {
3843
return false;
3944
}
4045
return true;

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414

1515
package zuo.biao.apijson.server;
1616

17-
import com.alibaba.fastjson.JSONObject;
18-
import org.springframework.web.bind.annotation.*;
19-
import zuo.biao.apijson.JSON;
17+
import org.springframework.web.bind.annotation.PathVariable;
18+
import org.springframework.web.bind.annotation.RequestMapping;
19+
import org.springframework.web.bind.annotation.RestController;
2020

21-
import java.io.UnsupportedEncodingException;
22-
import java.net.URLDecoder;
21+
import com.alibaba.fastjson.JSONObject;
2322

24-
import static zuo.biao.apijson.StringUtil.UTF_8;
23+
import zuo.biao.apijson.JSON;
2524

2625
/**request receiver and controller
2726
* @author Lemon

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,14 @@ public QueryConfig setPosition(int position) {
111111
* @return
112112
*/
113113
public String getLimitString() {
114-
return getLimitString(limit);// + 1);
114+
return getLimitString(page, limit);// + 1);
115115
}
116116
/**获取限制数量
117117
* @param limit
118118
* @return
119119
*/
120-
public static String getLimitString(int limit) {
121-
return limit <= 0 ? "" : " limit " + limit;
120+
public static String getLimitString(int page, int limit) {
121+
return limit <= 0 ? "" : " limit " + page*limit + ", " + limit;
122122
}
123123

124124
/**获取筛选方法
@@ -135,7 +135,6 @@ public static String getWhereString(Map<String, Object> where) {
135135
Set<String> set = where == null ? null : where.keySet();
136136
if (set != null && set.size() > 0) {
137137
String whereString = " where ";
138-
Object value;
139138
for (String key : set) {
140139
//避免筛选到全部 value = key == null ? null : where.get(key);
141140
if (key == null) {

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,14 @@ private JSONObject getArray(String parentPath, QueryConfig parentConfig, String
197197
// System.out.println(TAG + "getArray try { page = arrayObject.getIntValue(page); ..." +
198198
// " >> } catch (Exception e) {\n" + e.getMessage());
199199
}
200-
if (parseRelation) {
201-
request.remove("page");
202-
request.remove("count");
200+
if (count <= 0) {//解决count<=0导致没有查询结果
201+
count = 100;
203202
}
203+
204+
// if (parseRelation) {
205+
// request.remove("page");
206+
// request.remove("count");
207+
// }
204208
System.out.println(TAG + "getArray page = " + page + "; count = " + count);
205209

206210
QueryConfig config = new QueryConfig(count, page);

0 commit comments

Comments
 (0)