fix(BS-New-9): codegen Controller @RequestMapping 路径改写
BS-New-9: JNPF CodePreview 生成 Controller 默认 @RequestMapping('/api/example/{Class}')
- 28 个 form 都映射到 /api/example/Team 等固定路径
- 与 JNPF 平台 example 模块冲突, 后端注册歧义
修: 在 writeFileSync 前 post-process Controller.java
- 检测 @RequestMapping('/api/example/{PascalClassName}')
- 改写为 /api/{company}/{module}/{enCode}
- 用 --enCode 参数 (form enCode) 而非 PascalCase 推导
- fallback: opts.enCode || opts.module (用户不传 --enCode 时使用 module)
新增 --enCode 参数支持显式指定 form enCode
测试场 (testspace) 验证:
--enCode=teamtest → @RequestMapping('/api/ssw/testspace/teamtest') ✓
--enCode=projecttest → @RequestMapping('/api/ssw/testspace/projecttest') ✓
默认 (fallback) → @RequestMapping('/api/ssw/testspace/testspace') ✓
jxcj 2026-06-30 实战教训
This commit is contained in:
1 parent
2d9ea066e6
commit
21c10c2a8b
1 file changed
+28
@@ -41,6 +41,8 @@ interface CodegenOpts {
|
||||
description?: string
|
||||
dbLinkId?: string
|
||||
mainClassName?: string
|
||||
/** v0.12+ BS-New-9: 显式传 form enCode 用于 Controller @RequestMapping 路径 (避免从 mainClassName 推导类名) */
|
||||
enCode?: string
|
||||
enableFlow?: string
|
||||
out?: string
|
||||
/**
|
||||
@@ -574,6 +576,7 @@ export function buildFormCodegenCommand(): Command {
|
||||
.option('--description <desc>', '功能描述 (写到类注释)')
|
||||
.option('--dbLinkId <id>', '数据源 id (走业务库, 默认从 token.dbLinkId)')
|
||||
.option('--mainClassName <name>', '主表类名 (PascalCase, 默认从 enCode 自动转换: jxcj_develop_project → JxcjDevelopProject)')
|
||||
.option('--enCode <e>', 'v0.12+ BS-New-9: 显式指定 form enCode (Controller @RequestMapping 路径用, 默认取 opts.module)')
|
||||
.option('--enableFlow <0|1>', '是否启用流程 0/1', '0')
|
||||
.option('--out <path>', '输出目录 (默认 ./generated/${company}-${module}/)')
|
||||
// ⭐ 多模块归类 (v0.10+ 默认开启, 对齐 aibridge ssw-{appCode} 多模块 POM 结构)
|
||||
@@ -851,6 +854,31 @@ export function buildFormCodegenCommand(): Command {
|
||||
// 实测 jxcj 28 form: vue + xml 0 残留, 仅 .java 触发修复
|
||||
// 仍对 xml/vue 做检查 (WARN 而非改) — 防未来模板变动
|
||||
let contentToWrite = f.content
|
||||
// v0.12+ BS-New-9 fix (2026-06-30 jxcj): Controller @RequestMapping 路径改写
|
||||
// 根因: JNPF CodePreview 生成的 Controller 默认路径是 /api/example/{ClassName}
|
||||
// (走 JNPF 内置 example 模块), 28 个 form 都映射到 /api/example/Team 等
|
||||
// → 与 JNPF 自带的 example 路径冲突, 后端注册歧义
|
||||
// 镜像: web/webapi 创建业务模块时, 正确路径应为 /api/{company}/{module}/{enCode camelCase}
|
||||
// 例: /api/ssw/jxcj/team (company=ssw, module=jxcj, enCode=team)
|
||||
// 修: Controller.java 文件检测 @RequestMapping("/api/example/X"), 改成 /api/{company}/{module}/{enCode camelCase}
|
||||
// v0.12+ 修正: 用 form.enCode (而非 PascalCase→camelCase 推导) 保证路径与 JNPF form menu 一致
|
||||
if (f.path.includes('controller/') && f.path.endsWith('.java')) {
|
||||
// 用 opts.enCode 或默认 opts.module
|
||||
const enCodeForPath = opts.enCode || opts.module || 'unknown'
|
||||
const updated = contentToWrite.replace(
|
||||
/@RequestMapping\((["'])\/api\/example\/([A-Z][A-Za-z0-9]+)\1\)/g,
|
||||
(_m, q, className) => {
|
||||
// 优先用 opts.enCode (form enCode), 否则从 className 推导
|
||||
return `@RequestMapping(${q}/api/${opts.company || 'ssw'}/${opts.module || ''}/${enCodeForPath}${q})`
|
||||
},
|
||||
)
|
||||
if (updated !== contentToWrite) {
|
||||
const replaced = (contentToWrite.match(/@RequestMapping\((["'])\/api\/example\//g) || []).length
|
||||
contentToWrite = updated
|
||||
counts['__fix:bs-new-9-path'] = (counts['__fix:bs-new-9-path'] || 0) + replaced
|
||||
log.info(` BS-New-9: 改写 ${replaced} 个 Controller @RequestMapping 到 /api/${opts.company || 'ssw'}/${opts.module || ''}/${enCodeForPath}`)
|
||||
}
|
||||
}
|
||||
if (/\$\{[a-zA-Z]/.test(contentToWrite)) {
|
||||
if (f.path.endsWith('.java')) {
|
||||
const { fixed, count } = fixUnresolvedVelocityVars(contentToWrite)
|
||||
|
||||
Reference in new issue
Block a user