jeecgboot/JeecgBoot · error · JeecgBootException

该编码【${parentCode}】不存在,请核实!

Error message

该编码【${parentCode}】不存在,请核实!

What it means

Thrown as JeecgBootException from the generated tree service's queryListByCode method when the provided parentCode does not match any record in the database (the query returns null or an empty list). This method looks up a node by its parent-code field value to find its ID, then queries children by that ID. If the code does not resolve to exactly one record, it throws. The error message includes the offending parentCode value for debugging.

Source

Thrown at jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/resources/jeecg/code-template-online/default/tree/java/${bussiPackage}/${entityPackage}/service/impl/${entityName}ServiceImpl.javai:142

                }
            }else{
                if(!mapList.contains(data)){
                    mapList.add(data);
                }
            }
        }
        return mapList;
    }

    @Override
    public List<SelectTreeModel> queryListByCode(String parentCode) {
        String pid = ROOT_PID_VALUE;
        if (oConvertUtils.isNotEmpty(parentCode)) {
            LambdaQueryWrapper<${entityName}> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(${entityName}::get${pidFieldName?cap_first}, parentCode);
            List<${entityName}> list = baseMapper.selectList(queryWrapper);
            if (list == null || list.size() == 0) {
                throw new JeecgBootException("该编码【" + parentCode + "】不存在,请核实!");
            }
            if (list.size() > 1) {
                throw new JeecgBootException("该编码【" + parentCode + "】存在多个,请核实!");
            }
            pid = list.get(0).getId();
        }
        return baseMapper.queryListByPid(pid, null);
    }

    @Override
    public List<SelectTreeModel> queryListByPid(String pid) {
        if (oConvertUtils.isEmpty(pid)) {
            pid = ROOT_PID_VALUE;
        }
        return baseMapper.queryListByPid(pid, null);
    }

	/**

View on GitHub (pinned to 96fb33f5ec)

Solutions

  1. Verify the parentCode value exists in the database before calling queryListByCode.
  2. If the parent was deleted, inform the user and refresh the tree from the root.
  3. Ensure the code field column matches the entity's configured parent-code field name.
  4. For optional/null parentCode, pass null or empty to start from the root (ROOT_PID_VALUE).

Example fix

// before — caller passes unvalidated code
List<SelectTreeModel> tree = service.queryListByCode(userInputCode);  // throws
// after — validate first
if (oConvertUtils.isNotEmpty(userInputCode)) {
    LambdaQueryWrapper<Entity> check = new LambdaQueryWrapper<>();
    check.eq(Entity::getPid, userInputCode);
    if (baseMapper.selectList(check).isEmpty()) {
        return Result.error("Parent code not found: " + userInputCode);
    }
}
List<SelectTreeModel> tree = service.queryListByCode(userInputCode);
Defensive patterns

Strategy: validation

Validate before calling

// Validate parentCode exists before querying tree
if (oConvertUtils.isNotEmpty(parentCode)) {
    LambdaQueryWrapper<Entity> check = new LambdaQueryWrapper<>();
    check.eq(Entity::getPid, parentCode);
    List<Entity> found = baseMapper.selectList(check);
    if (found == null || found.isEmpty()) {
        return Result.error("Parent code not found: " + parentCode);
    }
}
List<SelectTreeModel> tree = service.queryListByCode(parentCode);

Type guard

boolean parentCodeExists(BaseMapper<Entity> mapper, String parentCode) {
    if (oConvertUtils.isEmpty(parentCode)) return true; // root query
    LambdaQueryWrapper<Entity> qw = new LambdaQueryWrapper<>();
    qw.eq(Entity::getPid, parentCode);
    List<Entity> list = mapper.selectList(qw);
    return list != null && list.size() == 1;
}

Try / catch

try {
    List<SelectTreeModel> tree = service.queryListByCode(parentCode);
} catch (JeecgBootException e) {
    if (e.getMessage() != null && e.getMessage().contains("不存在")) {
        return Result.error("The specified parent code does not exist: " + parentCode);
    }
    throw e;
}

Prevention

When it happens

Trigger: A request to query tree children by code where parentCode references a non-existent code value — e.g., a typo in the code parameter, the referenced parent record was deleted, or the code field uses a different column than expected.

Common situations: Frontend tree component passes an old/deleted node's code; user manually types a code that doesn't exist; data migration changed codes but frontend cached old values; the parent-code field name differs from what the template assumed (pidFieldName mismatch).

Related errors


AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14). Data as JSON: /api/errors/a21d8889c7cac023. Report an issue: GitHub.