Server:同步eclipse版至idea版;Client:同步adt版至studio版

This commit is contained in:
TommyLemon 2016-12-22 13:21:57 +08:00
parent 15e21f2da4
commit 086158c905
9 changed files with 46 additions and 40 deletions

View File

@ -33,8 +33,13 @@ public class JSON {
*/
public static boolean isJsonCorrect(String s) {
System.out.println(TAG + "isJsonCorrect <<<< " + s + " >>>>>>>");
if (s == null || s.equals("[]")
|| s.equals("{}") || s.equals("") || s.equals("[null]") || s.equals("{null}") || s.equals("null")) {
if (s == null
// || s.equals("[]")
// || s.equals("{}")
|| s.equals("")
|| s.equals("[null]")
|| s.equals("{null}")
|| s.equals("null")) {
return false;
}
return true;

View File

@ -38,7 +38,7 @@ public class RequestUtil {
}
public static JSONObject newArrayRequest() {
return new JSONRequest(new User().setSex(0)).toArray(10, 0, User.class.getSimpleName());
return new JSONRequest(new User()).toArray(5, 1, User.class.getSimpleName());
}
public static JSONObject newComplexRequest() {
@ -50,7 +50,7 @@ public class RequestUtil {
request.add(new JSONRequest(Comment.class.getSimpleName(), new JSONRequest("workId", "[]/Work/id")).
toArray(3, 0, Comment.class.getSimpleName()));
return request.toArray(2, 1);
return request.toArray(2, 0);
}
public static JSONObject newAccessErrorRequest() {

View File

@ -28,18 +28,18 @@ import apijson.demo.R;
public class SelectActivity extends Activity {
public static final String RESULT_JSON = "RESULT_JSON";
public static Intent createIntent(Context context) {
return new Intent(context, SelectActivity.class);
}
private Activity context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.select_activity);
context = this;
}
@ -47,33 +47,33 @@ public class SelectActivity extends Activity {
public void selectSingle(View v) {
select(QueryActivity.TYPE_SINGLE);
}
public void selectRely(View v) {
select(QueryActivity.TYPE_RELY);
}
public void selectArray(View v) {
select(QueryActivity.TYPE_ARRAY);
}
public void selectComplex(View v) {
select(QueryActivity.TYPE_COMPLEX);
}
public void selectAccessError(View v) {
select(QueryActivity.TYPE_ACCESS_ERROR);
}
public void selectAccessPermitted(View v) {
select(QueryActivity.TYPE_ACCESS_PERMITTED);
}
//click event,called form layout android:onClick >>>>>>>>>>>>>>>>
private String url;
private void select(int type) {
startActivityForResult(QueryActivity.createIntent(context, type, url), REQUEST_TO_QUERY);
}
private static final int REQUEST_TO_QUERY = 1;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
@ -85,14 +85,14 @@ public class SelectActivity extends Activity {
case REQUEST_TO_QUERY:
if (data == null) {
Toast.makeText(context, "onActivityResult data == null !!!", Toast.LENGTH_SHORT).show();
return;
} else {
url = data.getStringExtra(QueryActivity.RESULT_URL);
}
url = data.getStringExtra(QueryActivity.RESULT_URL);
break;
default:
break;
}
}
}

View File

@ -13,11 +13,5 @@
<string name="access_permitted">允许使用权限</string>
<string name="query">查询</string>
<string name="query_error">可能出现了一些问题,可以按照以下步骤解决:\n\n1.检查网络连接\n\n2.检查url是否为一个可用的IPV4地址\n\n3.长按[查询]按钮用浏览器发送请求\n\n4.查看目标服务器上的log\n\n5.再试一次</string>
<string name="demo_single">{\n&#160;&#160;&#160;\"User\":{\n&#160;&#160;&#160;&#160;&#160;&#160;\"id\":38710\n&#160;&#160;&#160;}\n}</string>
<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>
<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>
<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>
<string name="demo_wallet">{\n&#160;&#160;&#160;\"Wallet\":{\n&#160;&#160;&#160;&#160;&#160;&#160;\"userId\":38710\n&#160;&#160;&#160;}\n}</string>
<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>
</resources>

View File

@ -15,7 +15,7 @@
<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>
<string name="demo_single">{\n&#160;&#160;&#160;\"User\":{\n&#160;&#160;&#160;&#160;&#160;&#160;\"id\":38710\n&#160;&#160;&#160;}\n}</string>
<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>
<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>
<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>
<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>
<string name="demo_wallet">{\n&#160;&#160;&#160;\"Wallet\":{\n&#160;&#160;&#160;&#160;&#160;&#160;\"userId\":38710\n&#160;&#160;&#160;}\n}</string>
<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>

View File

@ -33,8 +33,13 @@ public class JSON {
*/
public static boolean isJsonCorrect(String s) {
System.out.println(TAG + "isJsonCorrect <<<< " + s + " >>>>>>>");
if (s == null || s.equals("[]")
|| s.equals("{}") || s.equals("") || s.equals("[null]") || s.equals("{null}") || s.equals("null")) {
if (s == null
// || s.equals("[]")
// || s.equals("{}")
|| s.equals("")
|| s.equals("[null]")
|| s.equals("{null}")
|| s.equals("null")) {
return false;
}
return true;

View File

@ -14,15 +14,14 @@ limitations under the License.*/
package zuo.biao.apijson.server;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.*;
import zuo.biao.apijson.JSON;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import static zuo.biao.apijson.StringUtil.UTF_8;
/**request receiver and controller
* @author Lemon
*/

View File

@ -111,14 +111,14 @@ public class QueryConfig {
* @return
*/
public String getLimitString() {
return getLimitString(limit);// + 1);
return getLimitString(page, limit);// + 1);
}
/**获取限制数量
* @param limit
* @return
*/
public static String getLimitString(int limit) {
return limit <= 0 ? "" : " limit " + limit;
public static String getLimitString(int page, int limit) {
return limit <= 0 ? "" : " limit " + page*limit + ", " + limit;
}
/**获取筛选方法
@ -135,7 +135,6 @@ public class QueryConfig {
Set<String> set = where == null ? null : where.keySet();
if (set != null && set.size() > 0) {
String whereString = " where ";
Object value;
for (String key : set) {
//避免筛选到全部 value = key == null ? null : where.get(key);
if (key == null) {

View File

@ -197,10 +197,14 @@ public class RequestParser {
// System.out.println(TAG + "getArray try { page = arrayObject.getIntValue(page); ..." +
// " >> } catch (Exception e) {\n" + e.getMessage());
}
if (parseRelation) {
request.remove("page");
request.remove("count");
if (count <= 0) {//解决count<=0导致没有查询结果
count = 100;
}
// if (parseRelation) {
// request.remove("page");
// request.remove("count");
// }
System.out.println(TAG + "getArray page = " + page + "; count = " + count);
QueryConfig config = new QueryConfig(count, page);