jeecgboot/JeecgBoot · error · JeecgBootException

操作失败,实体为空!

Error message

操作失败,实体为空!

What it means

Thrown by SysTableWhiteListServiceImpl.checkEntity when the sysTableWhiteList parameter is null. This JeecgBootException is the first guard in the entity validation chain, preventing NPEs in subsequent field-access calls. checkEntity is a private method called before any insert or update operation.

Source

Thrown at jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysTableWhiteListServiceImpl.java:62

    @Override
    public boolean edit(SysTableWhiteList sysTableWhiteList) {
        this.checkEntity(sysTableWhiteList);
        if (super.updateById(sysTableWhiteList)) {
            // 清空缓存
            whiteListHandler.clear();
            return true;
        }
        return false;
    }

    /**
     * 检查需要新增或更新的实体是否符合规范
     *
     * @param sysTableWhiteList
     */
    private void checkEntity(SysTableWhiteList sysTableWhiteList) {
        if (sysTableWhiteList == null) {
            throw new JeecgBootException("操作失败,实体为空!");
        }
        if (oConvertUtils.isEmpty(sysTableWhiteList.getTableName())) {
            throw new JeecgBootException("操作失败,表名不能为空!");
        }
        if (oConvertUtils.isEmpty(sysTableWhiteList.getFieldName())) {
            throw new JeecgBootException("操作失败,字段名不能为空!");
        }
        // 将表名和字段名转换成小写
        sysTableWhiteList.setTableName(sysTableWhiteList.getTableName().toLowerCase());
        sysTableWhiteList.setFieldName(sysTableWhiteList.getFieldName().toLowerCase());
        // 如果status为空,则默认启用
        if (oConvertUtils.isEmpty(sysTableWhiteList.getStatus())) {
            sysTableWhiteList.setStatus(CommonConstant.STATUS_1);
        }
    }

    @Override
    public boolean deleteByIds(String ids) {

View on GitHub (pinned to 96fb33f5ec)

Solutions

  1. Add @Valid and @NotNull annotations on the controller's @RequestBody parameter to reject null at the API boundary.
  2. Ensure the frontend always sends a valid JSON body, never an empty request.
  3. If calling programmatically, perform a null check before calling the service method.
  4. Add a global exception handler to convert this to a 400 Bad Request with a clear message.

Example fix

// before
private void checkEntity(SysTableWhiteList sysTableWhiteList) {
    if (sysTableWhiteList == null) {
        throw new JeecgBootException("操作失败,实体为空!");
    }
    // ...
}

// after — controller validates at the boundary
@PostMapping("/add")
public Result<?> add(@Valid @RequestBody @NotNull SysTableWhiteList entity) {
    service.save(entity);
    return Result.OK();
}
Defensive patterns

Strategy: validation

Validate before calling

// Validate entity is non-null before calling service
if (sysTableWhiteList == null) {
    return Result.error("操作失败,请求数据为空");
}
service.save(sysTableWhiteList);

Type guard

public boolean isWhitelistEntityValid(SysTableWhiteList entity) {
    return entity != null
        && oConvertUtils.isNotEmpty(entity.getTableName())
        && oConvertUtils.isNotEmpty(entity.getFieldName());
}

Try / catch

try {
    service.save(sysTableWhiteList);
} catch (JeecgBootException e) {
    if (e.getMessage().contains("实体为空")) {
        return Result.error("请求数据为空,请检查提交内容");
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling the service's save or update method (which internally calls checkEntity) with a null SysTableWhiteList argument. The controller may have accepted a null body or the caller constructed the entity conditionally and passed null.

Common situations: API endpoint called with an empty request body; the controller's @RequestBody is not validated with @NotNull; programmatic caller has a null reference due to a conditional construction path.

Related errors


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