{"record":{"id":"4814305db6dc36f6","repo":"elunez/eladmin","slug":"error-481430","errorCode":null,"errorMessage":"此环境不允许生成代码，请选择预览或者下载查看！","messagePattern":"此环境不允许生成代码，请选择预览或者下载查看！","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"warning","filePath":"eladmin-generator/src/main/java/me/zhengjie/rest/GeneratorController.java","lineNumber":94,"sourceCode":"    public ResponseEntity<HttpStatus> saveColumn(@RequestBody List<ColumnInfo> columnInfos){\n        generatorService.save(columnInfos);\n        return new ResponseEntity<>(HttpStatus.OK);\n    }\n\n    @ApiOperation(\"同步字段数据\")\n    @PostMapping(value = \"sync\")\n    public ResponseEntity<HttpStatus> syncColumn(@RequestBody List<String> tables){\n        for (String table : tables) {\n            generatorService.sync(generatorService.getColumns(table), generatorService.query(table));\n        }\n        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":76,"sourceCodeEnd":110,"githubUrl":"https://github.com/elunez/eladmin/blob/55fbf705956949697dbd68bf9003776609d3d029/eladmin-generator/src/main/java/me/zhengjie/rest/GeneratorController.java#L76-L110","documentation":"GeneratorController.generatorCode throws this when the code-generation action (type == 0) is requested but the generatorEnabled flag (eladmin generator.enabled, defaults false in prod configs) is false. Types 1 (preview) and 2 (download zip) remain available, hence the message telling you to preview or download instead. It is a safety switch so production systems never write generated files to disk.","triggerScenarios":"POST /api/generator/{tableName}/0 (generate into the project) while generator.enabled is false in the active profile's yml. Typical after deploying eladmin with the production config where code generation is deliberately disabled.","commonSituations":"Running against the prod profile where generator.enabled: false; copying eladmin.yml from a deployment template that disables generation; wanting to generate code on a server without editing the config.","solutions":["Use the frontend buttons '预览' (type=1) or '下载' (type=2) which are always allowed and give the same output without writing files.","If you truly need server-side generation, set generator.enabled: true in the active configuration and restart the service.","Better practice: download the zip (type=2) and generate locally, keeping the switch off in shared environments."],"exampleFix":"# before (eladmin.yml, prod)\ngenerator:\n  enabled: false\n\n# after\ngenerator:\n  enabled: true   # restart required; prefer download (type=2) instead","handlingStrategy":"validation","validationCode":"// Client: choose an allowed type when generation is disabled\nboolean generationEnabled = false; // from /api/generator config or deployment knowledge\nint type = generationEnabled ? 0 : 2; // download zip instead of server-side generate","typeGuard":"boolean isAllowedGeneratorType(boolean generatorEnabled, int type) {\n    return type == 1 || type == 2 || (type == 0 && generatorEnabled);\n}","tryCatchPattern":"try {\n    return post(\"/api/generator/\" + table + \"/0\");\n} catch (BadRequestException e) {\n    if (e.getMessage().contains(\"不允许生成代码\")) {\n        return post(\"/api/generator/\" + table + \"/2\"); // fallback to download\n    }\n    throw e;\n}","preventionTips":["Keep generator.enabled=false outside dev machines; prefer download (type=2) everywhere.","Make the frontend hide/disable the '生成' button when the flag is off.","Document for the team that type 0 writes files on the server and is environment-gated."],"tags":["code-generator","feature-flag","eladmin","configuration"],"backgroundTag":null,"analyzedSha":"55fbf705956949697dbd68bf9003776609d3d029","analyzedAt":"2026-08-14T11:56:12.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}