| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d803766 commit e609c86
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4568,10 +4568,20 @@ else if (userId instanceof Subquery) {} | |||
| 4568 | 4568 | Set<String> set = request.keySet(); //前面已经判断request是否为空 | |
| 4569 | 4569 | if (method == POST) { //POST操作 | |
| 4570 | 4570 | if (idIn != null) { | |
| 4571 | - throw new IllegalArgumentException(table + ":{} 里的 " + idInKey + ": value 不合法!POST 请求中不允许传 " + idInKey + " !"); | ||
| 4572 | - } | ||
| 4571 | + throw new IllegalArgumentException(table + ":{" + idInKey + ": value} 里的 key 不合法!POST 请求中不允许传 " + idInKey | ||
| 4572 | + + " 这种非字段命名 key !必须为 英文字母 开头且只包含 英文字母、数字、下划线的 字段命名!"); } | ||
| 4573 | + if (userIdIn != null) { | ||
| 4574 | + throw new IllegalArgumentException(table + ":{" + userIdInKey + ": value} 里的 key 不合法!POST 请求中不允许传 " + userIdInKey | ||
| 4575 | + + " 这种非字段命名 key !必须为 英文字母 开头且只包含 英文字母、数字、下划线的 字段命名!"); } | ||
| 4573 | 4576 | ||
| 4574 | 4577 | if (set != null && set.isEmpty() == false) { //不能直接return,要走完下面的流程 | |
| 4578 | + for (String k : set) { | ||
| 4579 | + if (StringUtil.isName(k) == false) { | ||
| 4580 | + throw new IllegalArgumentException(table + ":{" + k + ": value} 里的 key 不合法!POST 请求中不允许传 " + k | ||
| 4581 | + + " 这种非字段命名 key !必须为 英文字母 开头且只包含 英文字母、数字、下划线的 字段命名!"); | ||
| 4582 | + } | ||
| 4583 | + } | ||
| 4584 | + | ||
| 4575 | 4585 | String[] columns = set.toArray(new String[]{}); | |
| 4576 | 4586 | ||
| 4577 | 4587 | Collection<Object> valueCollection = request.values(); | |
@@ -4581,24 +4591,25 @@ else if (userId instanceof Subquery) {} | |||
| 4581 | 4591 | throw new Exception("服务器内部错误:\n" + TAG | |
| 4582 | 4592 | + " newSQLConfig values == null || values.length != columns.length !"); | |
| 4583 | 4593 | } | |
| 4584 | - column = (id == null ? "" : idKey + ",") + StringUtil.getString(columns); //set已经判断过不为空 | ||
| 4594 | + | ||
| 4595 | + column = (id == null ? "" : idKey + ",") + (userId == null ? "" : userIdKey + ",") + StringUtil.getString(columns); //set已经判断过不为空 | ||
| 4585 | 4596 | ||
| 4586 | - List<List<Object>> valuess = new ArrayList<>(1); | ||
| 4587 | - List<Object> items; //(item0, item1, ...) | ||
| 4588 | - if (id == null) { //数据库自增 id | ||
| 4589 | - items = Arrays.asList(values); //FIXME 是否还需要进行 add 或 remove 操作?Arrays.ArrayList 不允许修改,会抛异常 | ||
| 4590 | - } | ||
| 4591 | - else { | ||
| 4592 | - int size = columns.length + (id == null ? 0 : 1); //以key数量为准 | ||
| 4597 | + int idCount = id == null ? (userId == null ? 0 : 1) : (userId == null ? 1 : 2); | ||
| 4598 | + int size = idCount + columns.length; // 以 key 数量为准 | ||
| 4593 | 4599 | ||
| 4594 | - items = new ArrayList<>(size); | ||
| 4595 | - items.add(id); //idList.get(i)); //第0个就是id | ||
| 4600 | + List<Object> items = new ArrayList<>(size); // VALUES(item0, item1, ...) | ||
| 4601 | + if (id != null) { | ||
| 4602 | + items.add(id); // idList.get(i)); // 第 0 个就是 id | ||
| 4603 | + } | ||
| 4604 | + if (userId != null) { | ||
| 4605 | + items.add(userId); // idList.get(i)); // 第 1 个就是 userId | ||
| 4606 | + } | ||
| 4596 | 4607 | ||
| 4597 | - for (int j = 1; j < size; j++) { | ||
| 4598 | - items.add(values[j-1]); //从第1个开始,允许"null" | ||
| 4599 | - } | ||
| 4608 | + for (int j = 0; j < values.length; j++) { | ||
| 4609 | + items.add(values[j]); // 从第 1 个开始,允许 "null" | ||
| 4600 | 4610 | } | |
| 4601 | 4611 | ||
| 4612 | + List<List<Object>> valuess = new ArrayList<>(1); | ||
| 4602 | 4613 | valuess.add(items); | |
| 4603 | 4614 | config.setValues(valuess); | |
| 4604 | 4615 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments