{"record":{"id":"7fa79fde3119e961","repo":"elunez/eladmin","slug":"error-7fa79f","errorCode":null,"errorMessage":"没有这个选项","messagePattern":"没有这个选项","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"eladmin-generator/src/main/java/me/zhengjie/rest/GeneratorController.java","lineNumber":105,"sourceCode":"        return new ResponseEntity<>(HttpStatus.OK);\n    }\n\n    @ApiOperation(\"生成代码\")\n    @PostMapping(value = \"/{tableName}/{type}\")\n    public ResponseEntity<Object> generatorCode(@PathVariable String tableName, @PathVariable Integer type, HttpServletRequest request, HttpServletResponse response){\n        if(!generatorEnabled && type == 0){\n            throw new BadRequestException(\"此环境不允许生成代码，请选择预览或者下载查看！\");\n        }\n        switch (type){\n            // 生成代码\n            case 0: generatorService.generator(genConfigService.find(tableName), generatorService.getColumns(tableName));\n                    break;\n            // 预览\n            case 1: return generatorService.preview(genConfigService.find(tableName), generatorService.getColumns(tableName));\n            // 打包\n            case 2: generatorService.download(genConfigService.find(tableName), generatorService.getColumns(tableName), request, response);\n                    break;\n            default: throw new BadRequestException(\"没有这个选项\");\n        }\n        return new ResponseEntity<>(HttpStatus.OK);\n    }\n}\n","sourceCodeStart":87,"sourceCodeEnd":110,"githubUrl":"https://github.com/elunez/eladmin/blob/55fbf705956949697dbd68bf9003776609d3d029/eladmin-generator/src/main/java/me/zhengjie/rest/GeneratorController.java#L87-L110","documentation":"GeneratorController.generatorCode switches on the path variable 'type' and only accepts 0 (generate), 1 (preview), 2 (download). Any other integer falls to the default branch and throws BadRequestException('没有这个选项'). It is pure input validation on the URL path.","triggerScenarios":"POST /api/generator/{tableName}/3 (or any type other than 0, 1, 2). Happens with hand-crafted requests, outdated frontend sending a type value the backend does not support, or typos in scripts.","commonSituations":"Version skew between an updated frontend (new action type) and older backend; manual curl/API testing; browser autofill or URL editing producing an unexpected integer.","solutions":["Send a valid type: 0 to generate, 1 to preview, 2 to download.","Align frontend and backend versions so the UI only emits supported type values.","If you are adding a new generation mode, extend the switch and keep the default branch as the guard."],"exampleFix":"// before\ncurl -X POST http://host/api/generator/sys_user/3\n\n// after\ncurl -X POST http://host/api/generator/sys_user/2   // 0=generate 1=preview 2=download","handlingStrategy":"validation","validationCode":"// Client: whitelist the type before calling\nint type = params.type;\nif (type < 0 || type > 2) {\n    throw new Error(\"type must be 0(生成) 1(预览) 2(下载)\");\n}\npost(`/api/generator/${table}/${type}`);","typeGuard":"function isValidGeneratorType(t) {\n  return [0, 1, 2].includes(t);\n}","tryCatchPattern":"try {\n    return post(\"/api/generator/\" + table + \"/\" + type);\n} catch (BadRequestException e) {\n    if (\"没有这个选项\".equals(e.getMessage())) throw new IllegalArgumentException(\"Unsupported generator type: \" + type);\n    throw e;\n}","preventionTips":["Pin frontend and backend to compatible versions so the UI only emits 0/1/2.","When adding a new generation mode, add it to the switch before shipping clients that use it.","Prefer a request-body enum over a magic int path variable in future API designs."],"tags":["code-generator","validation","eladmin","bad-request"],"backgroundTag":null,"analyzedSha":"55fbf705956949697dbd68bf9003776609d3d029","analyzedAt":"2026-08-14T11:56:12.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}