jeecgboot/JeecgBoot · error · JeecgBootException
该编码【${pcode}】不存在,请核实!
Error message
该编码【${pcode}】不存在,请核实! What it means
SysCategoryServiceImpl.queryListByCode resolves a tree parent by its category code (pcode). If no sys_category row matches the code, there is no parent id to build the tree from, so a JeecgBootException is thrown rather than returning an ambiguous/empty result.
Source
Thrown at jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysCategoryServiceImpl.java:80
sysCategory.setPid(ISysCategoryService.ROOT_PID_VALUE);
}else{
//如果当前节点父ID不为空 则设置父节点的hasChild 为1
SysCategory parent = baseMapper.selectById(sysCategory.getPid());
if(parent!=null && !ISysCategoryService.HAS_CHILD.equals(parent.getHasChild())){
parent.setHasChild(ISysCategoryService.HAS_CHILD);
baseMapper.updateById(parent);
}
}
baseMapper.updateById(sysCategory);
}
@Override
public List<TreeSelectModel> queryListByCode(String pcode) throws JeecgBootException{
String pid = ROOT_PID_VALUE;
if(oConvertUtils.isNotEmpty(pcode)) {
List<SysCategory> list = baseMapper.selectList(new LambdaQueryWrapper<SysCategory>().eq(SysCategory::getCode, pcode));
if(list==null || list.size() ==0) {
throw new JeecgBootException("该编码【"+pcode+"】不存在,请核实!");
}
if(list.size()>1) {
throw new JeecgBootException("该编码【"+pcode+"】存在多个,请核实!");
}
pid = list.get(0).getId();
}
return baseMapper.queryListByPid(pid,null);
}
@Override
public List<TreeSelectModel> queryListByPid(String pid) {
if(oConvertUtils.isEmpty(pid)) {
pid = ROOT_PID_VALUE;
}
return baseMapper.queryListByPid(pid,null);
}
@OverrideView on GitHub (pinned to 96fb33f5ec)
Solutions
- Verify the pcode exists: SELECT * FROM sys_category WHERE code = ?.
- Use the correct code or create the category with that code first.
- Treat an empty result as 'use root' only if business logic permits, otherwise surface a clear error to the caller.
Example fix
// before
List<TreeSelectModel> tree = sysCategoryService.queryListByCode("regin"); // typo
// after
String code = "region";
if (categoryCodeMissing(code)) {
return Collections.emptyList(); // or a user-facing error
}
List<TreeSelectModel> tree = sysCategoryService.queryListByCode(code); Defensive patterns
Strategy: validation
Validate before calling
// Confirm the category code exists before resolving the tree.
List<SysCategory> rows = sysCategoryMapper.selectList(
new LambdaQueryWrapper<SysCategory>().eq(SysCategory::getCode, pcode));
if (rows == null || rows.isEmpty()) {
return Collections.emptyList(); // or a user-facing error
} Type guard
public boolean categoryCodeExists(String code) {
Long n = baseMapper.selectCount(
new LambdaQueryWrapper<SysCategory>().eq(SysCategory::getCode, code));
return n != null && n > 0;
} Try / catch
try {
return sysCategoryService.queryListByCode(pcode);
} catch (JeecgBootException e) {
if (e.getMessage() != null && e.getMessage().contains("不存在")) {
return Collections.emptyList();
}
throw e;
} Prevention
- Validate pcode against sys_category before calling queryListByCode.
- Centralize category codes as constants/dictionary entries.
- Return empty list (or a clear message) instead of letting the exception reach users.
When it happens
Trigger: Calling queryListByCode with a pcode that has no matching sys_category.code row (typo, deleted category, code from another environment).
Common situations: Dictionary/category code typo in configuration; category was deleted but referencing code remains; code configured per-tenant and missing in the current tenant; case mismatch.
Related errors
AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14).
Data as JSON: /api/errors/f0e432c823aed074.
Report an issue: GitHub.