| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 95d281d commit 2b6a2a9
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -152,7 +152,7 @@ public JSONRequest setSubqueryRange(String range) { | |||
| 152 | 152 | } | |
| 153 | 153 | ||
| 154 | 154 | /**set from for Subquery | |
| 155 | - * @param range | ||
| 155 | + * @param from | ||
| 156 | 156 | * @return | |
| 157 | 157 | */ | |
| 158 | 158 | public JSONRequest setSubqueryFrom(String from) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -70,24 +70,35 @@ public abstract class AbstractParser<T extends Object> implements Parser<T>, Par | |||
| 70 | 70 | public static boolean IS_PRINT_REQUEST_ENDTIME_LOG = false; | |
| 71 | 71 | ||
| 72 | 72 | ||
| 73 | - public static int DEFAULT_QUERY_COUNT = 10; | ||
| 73 | + /** | ||
| 74 | + * 分页页码是否从 1 开始,默认为从 0 开始 | ||
| 75 | + */ | ||
| 76 | + public static boolean IS_START_FROM_1 = false; | ||
| 74 | 77 | public static int MAX_QUERY_PAGE = 100; | |
| 78 | + public static int DEFAULT_QUERY_COUNT = 10; | ||
| 75 | 79 | public static int MAX_QUERY_COUNT = 100; | |
| 76 | 80 | public static int MAX_UPDATE_COUNT = 10; | |
| 77 | 81 | public static int MAX_SQL_COUNT = 200; | |
| 78 | 82 | public static int MAX_OBJECT_COUNT = 5; | |
| 79 | 83 | public static int MAX_ARRAY_COUNT = 5; | |
| 80 | 84 | public static int MAX_QUERY_DEPTH = 5; | |
| 81 | 85 | ||
| 86 | + public boolean isStartFrom1() { | ||
| 87 | + return IS_START_FROM_1; | ||
| 88 | + } | ||
| 82 | 89 | @Override | |
| 83 | - public int getDefaultQueryCount() { | ||
| 84 | - return DEFAULT_QUERY_COUNT; | ||
| 90 | + public int getMinQueryPage() { | ||
| 91 | + return isStartFrom1() ? 1 : 0; | ||
| 85 | 92 | } | |
| 86 | 93 | @Override | |
| 87 | 94 | public int getMaxQueryPage() { | |
| 88 | 95 | return MAX_QUERY_PAGE; | |
| 89 | 96 | } | |
| 90 | 97 | @Override | |
| 98 | + public int getDefaultQueryCount() { | ||
| 99 | + return DEFAULT_QUERY_COUNT; | ||
| 100 | + } | ||
| 101 | + @Override | ||
| 91 | 102 | public int getMaxQueryCount() { | |
| 92 | 103 | return MAX_QUERY_COUNT; | |
| 93 | 104 | } | |
@@ -1183,23 +1194,28 @@ public JSONObject onObjectParse(final JSONObject request | |||
| 1183 | 1194 | if (max < 0) { | |
| 1184 | 1195 | max = 0; | |
| 1185 | 1196 | } | |
| 1197 | + int min = getMinQueryPage(); | ||
| 1198 | + | ||
| 1199 | + page += min; | ||
| 1200 | + max += min; | ||
| 1186 | 1201 | ||
| 1187 | 1202 | JSONObject pagination = new JSONObject(true); | |
| 1188 | 1203 | Object explain = rp.get(JSONResponse.KEY_EXPLAIN); | |
| 1189 | 1204 | if (explain instanceof JSONObject) { | |
| 1190 | 1205 | pagination.put(JSONResponse.KEY_EXPLAIN, explain); | |
| 1191 | 1206 | } | |
| 1207 | + | ||
| 1192 | 1208 | pagination.put(JSONResponse.KEY_TOTAL, total); | |
| 1193 | 1209 | pagination.put(JSONRequest.KEY_COUNT, count); | |
| 1194 | 1210 | pagination.put(JSONRequest.KEY_PAGE, page); | |
| 1195 | 1211 | pagination.put(JSONResponse.KEY_MAX, max); | |
| 1196 | 1212 | pagination.put(JSONResponse.KEY_MORE, page < max); | |
| 1197 | - pagination.put(JSONResponse.KEY_FIRST, page == 0); | ||
| 1213 | + pagination.put(JSONResponse.KEY_FIRST, page == min); | ||
| 1198 | 1214 | pagination.put(JSONResponse.KEY_LAST, page == max); | |
| 1199 | 1215 | ||
| 1200 | 1216 | putQueryResult(pathPrefix + JSONResponse.KEY_INFO, pagination); | |
| 1201 | 1217 | ||
| 1202 | - if (total <= count*page) { | ||
| 1218 | + if (total <= count*(page - min)) { | ||
| 1203 | 1219 | query = JSONRequest.QUERY_TOTAL;//数量不够了,不再往后查询 | |
| 1204 | 1220 | } | |
| 1205 | 1221 | } | |
@@ -1285,14 +1301,16 @@ public JSONArray onArrayParse(JSONObject request, String parentPath, String name | |||
| 1285 | 1301 | query2 = JSONRequest.QUERY_ALL; | |
| 1286 | 1302 | break; | |
| 1287 | 1303 | default: | |
| 1288 | - throw new IllegalArgumentException(path + "/" + JSONRequest.KEY_QUERY + ":value 中 value 的值不合法!必须在 [0,1,2] 或 [TABLE, TOTAL, ALL] 内 !"); | ||
| 1304 | + throw new IllegalArgumentException(path + "/" + JSONRequest.KEY_QUERY + ":value 中 value 的值不合法!必须在 [0, 1, 2] 或 [TABLE, TOTAL, ALL] 内 !"); | ||
| 1289 | 1305 | } | |
| 1290 | 1306 | } | |
| 1291 | 1307 | ||
| 1292 | - int page2 = page == null ? 0 : page; | ||
| 1308 | + int minPage = getMinQueryPage(); // 兼容各种传 0 或 null/undefined 自动转 0 导致的问题 | ||
| 1309 | + int page2 = page == null || page == 0 ? 0 : page - minPage; | ||
| 1310 | + | ||
| 1293 | 1311 | int maxPage = getMaxQueryPage(); | |
| 1294 | 1312 | if (page2 < 0 || page2 > maxPage) { | |
| 1295 | - throw new IllegalArgumentException(path + "/" + JSONRequest.KEY_PAGE + ":value 中 value 的值不合法!必须在 0-" + maxPage + " 内 !"); | ||
| 1313 | + throw new IllegalArgumentException(path + "/" + JSONRequest.KEY_PAGE + ":value 中 value 的值不合法!必须在 " + minPage + "-" + maxPage + " 内 !"); | ||
| 1296 | 1314 | } | |
| 1297 | 1315 | ||
| 1298 | 1316 | //不用total限制数量了,只用中断机制,total只在query = 1,2的时候才获取 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -83,8 +83,9 @@ JSONObject parseCorrectRequest(RequestMethod method, String tag, int version, St | |||
| 83 | 83 | ||
| 84 | 84 | ObjectParser<T> createObjectParser(JSONObject request, String parentPath, SQLConfig<T> arrayConfig, boolean isSubquery, boolean isTable, boolean isArrayMainTable) throws Exception; | |
| 85 | 85 | ||
| 86 | - int getDefaultQueryCount(); | ||
| 86 | + int getMinQueryPage(); | ||
| 87 | 87 | int getMaxQueryPage(); | |
| 88 | + int getDefaultQueryCount(); | ||
| 88 | 89 | int getMaxQueryCount(); | |
| 89 | 90 | int getMaxUpdateCount(); | |
| 90 | 91 | int getMaxSQLCount(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments