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
- Add @Valid and @NotNull annotations on the controller's @RequestBody parameter to reject null at the API boundary.
- Ensure the frontend always sends a valid JSON body, never an empty request.
- If calling programmatically, perform a null check before calling the service method.
- 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
- Add @NotNull and @Valid on the controller @RequestBody parameter.
- Ensure the frontend always sends a valid JSON body.
- Perform a null check before calling the service method.
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
- 操作失败,表名不能为空!
- 操作失败,字段名不能为空!
- 表名不合法,存在SQL注入风险!--->{table}
- 字段不合法,存在SQL注入风险!--->{field}
- 下载失败,存在非法文件类型:{suffix}
AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14).
Data as JSON: /api/errors/33fd9a33902ab594.
Report an issue: GitHub.