Tencent/APIJSON · error · IllegalArgumentException
{method}请求,{name}/{key} 里面 {idKey},{idInKey},{idKey}{}@ 至少传其
Error message
{method}请求,{name}/{key} 里面 {idKey},{idInKey},{idKey}{}@ 至少传其中一个! What it means
Thrown by verifyId with atLeastOne=true (batch-write requests) when none of id, id{}, id{}@ is present in the table object. APIJSON refuses UPDATE/DELETE without a row selector because that would update every row.
Source
Thrown at APIJSONORM/src/main/java/apijson/orm/AbstractVerifier.java:768
throw new IllegalArgumentException(method + "请求," + name + "/" + key
+ " 里面的 " + idKey + ":value 中value的类型只能是 Long 或 String !");
}
//批量修改或删除
String idInKey = idKey + "{}";
// id引用, 格式: "id{}@": "sql"
String idRefInKey = getString(robj, idKey + "{}@");
L idIn = null;
try {
idIn = get(robj, idInKey); //如果必须传 id{} ,可在Request表中配置NECESSARY
} catch (Exception e) {
throw new IllegalArgumentException(method + "请求," + name + "/" + key
+ " 里面的 " + idInKey + ":value 中value的类型只能是 [Long] !");
}
if (idIn == null) {
if (atLeastOne && id == null && idRefInKey == null) {
throw new IllegalArgumentException(method + "请求," + name + "/" + key
+ " 里面 " + idKey + "," + idInKey + "," + (idKey + "{}@") + " 至少传其中一个!");
}
} else {
if (idIn.size() > maxUpdateCount) { //不允许一次操作 maxUpdateCount 条以上记录
throw new IllegalArgumentException(method + "请求," + name + "/" + key
+ " 里面的 " + idInKey + ":[] 中[]的长度不能超过 " + maxUpdateCount + " !");
}
//解决 id{}: ["1' OR 1='1'))--"] 绕过id{}限制
//new ArrayList<Long>(idIn) 不能检查类型,Java泛型擦除问题,居然能把 ["a"] 赋值进去还不报错
for (int i = 0; i < idIn.size(); i++) {
Object o = idIn.get(i);
if (o == null) {
throw new IllegalArgumentException(method + "请求," + name + "/" + key
+ " 里面的 " + idInKey + ":[] 中所有项都不能为 [ null, <= 0 的数字, 空字符串 \"\" ] 中任何一个 !");
}
if (o instanceof Number) {
//解决 Windows mysql-5.6.26-winx64 等低于 5.7 的 MySQL 可能 id{}: [0] 生成 id IN(0) 触发 MySQL bug 导致忽略 IN 条件
//例如 UPDATE `apijson`.`TestRecord` SET `testAccountId` = -1 WHERE ( (`id` IN (0)) AND (`userId`= 82001) )View on GitHub (pinned to 5284052872)
Solutions
- Add the target row id: {"User":{"id":82001,"name":"a"}}
- For batch, add id{}:[...] or an id reference id{}@:"..."
- If you genuinely need a WHERE-less operation, reconsider — APIJSON forbids it by design
Example fix
// before
{"User":{"name":"a"}}
// after
{"User":{"id":82001,"name":"a"}} Defensive patterns
Strategy: validation
Validate before calling
function hasRowSelector(obj, idKey = 'id') {
return obj[idKey] != null || obj[idKey + '{}'] != null || obj[idKey + '{}@'] != null;
}
// before PUT/DELETE: if (!hasRowSelector(body[table])) throw new Error('id/id{}/id{}@ required'); Try / catch
catch (e) { if (/至少传其中一个/.test(e.message)) promptUserToSelectRows(); else throw e; } Prevention
- Make the record id a mandatory parameter in your update/delete client functions
- Disable the submit button until a target row is selected in edit UIs
When it happens
Trigger: PUT /put with {"User":{"name":"a"}} — no "id", no "id{}", no "id{}@" key in the User object of a PUT/DELETE request.
Common situations: Client builds the update body from a form and forgets to carry the record id; copy-pasting a POST body into a PUT; intending an id reference (id{}@:"sql") but mistyping the key.
Related errors
- Cannot convert value of type " + value.getClass().getName()
- 字符 " + function + " 不合法!
- 字符 " + method + " 不合法!函数的名称 function 不能为空且必须符合方法命名规范!总体必须为 f
- 字符 {} 不合法!远程函数不允许指定类名!且必须为 function(key0,key1,...) 这种单函数格式!\
- {}: { @key(): value } 对应存储过程 value 中字符 {} 不合法!`schema` 当有 `
AI-assisted analysis of Tencent/APIJSON@5284052872 (2026-08-14).
Data as JSON: /api/errors/74abaffcd24b28ad.
Report an issue: GitHub.