{"record":{"id":"e6e333e1c05e15d8","repo":"elunez/eladmin","slug":"entity-parameter-is-value","errorCode":null,"errorMessage":"{entity} 不存在: {parameter} is {value}","messagePattern":"(.+?) 不存在: (.+?) is (.+?)","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"eladmin-common/src/main/java/me/zhengjie/utils/ValidationUtil.java","lineNumber":36,"sourceCode":"import cn.hutool.core.lang.Validator;\nimport cn.hutool.core.util.ObjectUtil;\nimport me.zhengjie.exception.BadRequestException;\n\n/**\n * 验证工具\n *\n * @author Zheng Jie\n * @date 2018-11-23\n */\npublic class ValidationUtil {\n\n    /**\n     * 验证空\n     */\n    public static void isNull(Object obj, String entity, String parameter , Object value){\n        if(ObjectUtil.isNull(obj)){\n            String msg = entity + \" 不存在: \"+ parameter +\" is \"+ value;\n            throw new BadRequestException(msg);\n        }\n    }\n\n  /**\n   * 验证是否为邮箱\n   */\n  public static boolean isEmail(String email) {\n    return Validator.isEmail(email);\n  }\n}\n","sourceCodeStart":18,"sourceCodeEnd":47,"githubUrl":"https://github.com/elunez/eladmin/blob/55fbf705956949697dbd68bf9003776609d3d029/eladmin-common/src/main/java/me/zhengjie/utils/ValidationUtil.java#L18-L47","documentation":"ValidationUtil.isNull is a generic existence guard: when the looked-up object is null it throws BadRequestException with a message of the form '<entity> 不存在: <parameter> is <value>'. Service layers (e.g. AppServiceImpl.findById, many modules) call it right after repository.findById(...).orElseGet(X::new) to convert an empty lookup into a 400 response.","triggerScenarios":"Any GET /api/xxx/{id} (or update/delete) where the entity with that id does not exist in the database — e.g. requesting App with id=99 after orElseGet(App::new) leaves id null. Also stale frontend state holding an id deleted by another user or after a re-seeded database.","commonSituations":"Deleted or never-created records still referenced by the frontend; wrong environment (querying dev data from a prod-configured client); id type mismatch (passing a String where Long is expected causing a lookup miss); concurrent deletion between list and detail views.","solutions":["Verify the id actually exists (GET the list endpoint or query the table) and correct the client.","If the record was deleted, refresh the frontend list/cache so stale ids are not reused.","Check you are pointing at the right database/environment for the id you hold.","For creators of APIs: return 404 semantics or a localized message instead of leaking 'is null' style details."],"exampleFix":"// before\nApp app = appRepository.findById(id).orElseGet(App::new);\nValidationUtil.isNull(app.getId(), \"App\", \"id\", id);\n\n// after: fail with a clear 404-style message\nApp app = appRepository.findById(id)\n        .orElseThrow(() -> new BadRequestException(\"App 不存在: id is \" + id));","handlingStrategy":"validation","validationCode":"// Caller: verify existence before acting on an id\nboolean exists = appRepository.existsById(id);\nif (!exists) {\n    return notFound(\"App id=\" + id); // avoid invoking downstream logic\n}\nAppDto dto = appService.findById(id);","typeGuard":"private boolean isExistingId(Long id) {\n    return id != null && id > 0 && appRepository.existsById(id);\n}","tryCatchPattern":"try {\n    return service.findById(id);\n} catch (BadRequestException e) {\n    if (e.getMessage().contains(\"不存在\")) return ResponseEntity.notFound().build();\n    throw e;\n}","preventionTips":["Refresh lists/caches after deletions so stale ids are never submitted.","Use existsById() or orElseThrow with a domain-specific message instead of orElseGet + isNull for clearer failures.","Validate id format and range at the controller boundary.","Confirm you are querying the same environment/database your ids came from."],"tags":["validation","not-found","eladmin","crud"],"backgroundTag":null,"analyzedSha":"55fbf705956949697dbd68bf9003776609d3d029","analyzedAt":"2026-08-14T11:56:12.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}