Skip to content

fix: freemarker 生成错误#210

Merged
Charles7c merged 1 commit into
continew-org:devfrom
luoqiz:fix-gen
Apr 3, 2026
Merged

fix: freemarker 生成错误#210
Charles7c merged 1 commit into
continew-org:devfrom
luoqiz:fix-gen

Conversation

@luoqiz
Copy link
Copy Markdown
Contributor

@luoqiz luoqiz commented Apr 3, 2026

PR 类型

  • 新 feature
  • Bug 修复
  • 功能增强
  • 文档变更
  • 代码样式变更
  • 重构
  • 性能改进
  • 单元测试
  • CI/CD
  • 其他

PR 目的

解决方案

PR 测试

Changelog

模块 Changelog Related issues

其他信息

提交前确认

  • PR 代码经过了完整测试,并且通过了代码规范检查
  • 已经完整填写 Changelog,并链接到了相关 issues
  • PR 代码将要提交到 dev 分支

Summary by CodeRabbit

发布说明

  • Bug Fixes
    • 改善代码生成器模板引擎的版本兼容性,提升生成结果的稳定性与一致性。
    • 优化模板中数值格式化规则,生成的 SQL 与数值插入更精确,减少格式相关问题并降低后续手工调整需求。

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 3, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5e047fb0-ba23-4d8e-b327-17a9bb86e6cd

📥 Commits

Reviewing files that changed from the base of the PR and between e7fa75c and ac0e9ab.

📒 Files selected for processing (2)
  • continew-plugin/continew-plugin-generator/src/main/java/top/continew/admin/generator/service/impl/GeneratorServiceImpl.java
  • continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/Menu.ftl
✅ Files skipped from review due to trivial changes (2)
  • continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/Menu.ftl
  • continew-plugin/continew-plugin-generator/src/main/java/top/continew/admin/generator/service/impl/GeneratorServiceImpl.java

📝 Walkthrough

Walkthrough

更新 Freemarker 配置与模板:在代码中将 DefaultObjectWrapperBuilder 的版本来源改为 Configuration.getVersion();在 Menu.ftl 模板顶部添加数值格式化设置以控制数值输出格式(例如 Snowflake ID 在生成 SQL 时的呈现)。

Changes

Cohort / File(s) Summary
Freemarker 引擎配置
continew-plugin/continew-plugin-generator/src/main/java/top/continew/admin/generator/service/impl/GeneratorServiceImpl.java
DefaultObjectWrapperBuilder 的版本参数从硬编码 Configuration.VERSION_2_3_33 改为 Configuration.getVersion(),以动态使用当前配置的 Freemarker 版本。
模板数值格式设置
continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/Menu.ftl
在模板顶部添加 FreeMarker 指令以设置数值格式(<#setting number_format ...>),规范化模板中数值(如 Snowflake ID)的输出格式,影响生成的 SQL 中数值的呈现。

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 配置轻点改,版本自会知,
数字排得整,SQL笑开眉。
小改带来序,模板更安宁,
兔子一跳舞,代码又一枝。

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题简洁地概括了主要变更——修复 FreeMarker 生成错误,与代码变更(更新 DefaultObjectWrapperBuilder 和 FreeMarker 模板格式)直接相关。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@continew-plugin/continew-plugin-generator/src/main/java/top/continew/admin/generator/service/impl/GeneratorServiceImpl.java`:
- Line 312: 当前在构造 DefaultObjectWrapper 时使用了 Configuration.getVersion()(见
DefaultObjectWrapperBuilder 的构造调用),这会随运行时 FreeMarker 版本变化带来不确定行为;请改为使用固定的
FreeMarker 版本常量(例如 Configuration.VERSION_2_3_33 或项目实际使用的常量)作为
DefaultObjectWrapperBuilder 的构造参数,以保证向后兼容性并避免运行时行为改变。
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 79f18654-5e8f-48e7-be88-07a66e34cc92

📥 Commits

Reviewing files that changed from the base of the PR and between 1e9b8f4 and e7fa75c.

📒 Files selected for processing (2)
  • continew-plugin/continew-plugin-generator/src/main/java/top/continew/admin/generator/service/impl/GeneratorServiceImpl.java
  • continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/Menu.ftl

// 在模板中允许使用静态方法
if (engine instanceof FreemarkerEngine freemarkerEngine) {
DefaultObjectWrapper wrapper = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_33).build();
DefaultObjectWrapper wrapper = new DefaultObjectWrapperBuilder(Configuration.getVersion()).build();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# 检查项目中 FreeMarker 的版本和 Configuration 类的方法

echo "=== 查找 FreeMarker 依赖版本 ==="
fd -e xml -e gradle 'pom.xml|build.gradle' --exec rg -A2 -B2 'freemarker'

echo -e "\n=== 查找 Configuration 类的使用情况 ==="
rg -n "Configuration\.(getVersion|VERSION_)" --type java -C2

Repository: continew-org/continew-admin

Length of output: 1260


🌐 Web query:

FreeMarker Configuration.getVersion() static method API documentation

💡 Result:

Yes, FreeMarker has a static method Configuration.getVersion that returns the Version object representing the FreeMarker version (major.minor.micro numbers and qualifiers). It is documented in the official FreeMarker 2.3.34 JavaDoc. Signature: public static Version getVersion Description: Returns FreeMarker version information, most importantly the major.minor.micro version numbers. Do NOT use this as the value of the incompatible_improvements setting (as the parameter to Configuration(Version)), as then your application can break when you upgrade FreeMarker! Use a constant value, like VERSION_2_3_34, to protect your application from fixes/changes that aren't entirely backward compatible. This method has been present since at least FreeMarker 2.3.20, and is available in the latest version 2.3.34 (as of 2026-04-03). Official documentation: https://freemarker.apache.org/docs/api/freemarker/template/Configuration.html#getVersion Note: There is also a deprecated getVersionNumber that returns a String.

Citations:


使用 FreeMarker 的静态常量而非 Configuration.getVersion()

Configuration.getVersion() 是有效的静态方法,但根据 FreeMarker 官方文档,不应该将其用作 incompatible_improvements 设置的值(即 DefaultObjectWrapperBuilder 的构造参数)。当 FreeMarker 版本升级时,使用运行时版本号会导致应用行为改变。

建议改为使用固定的版本常量,如 Configuration.VERSION_2_3_33 或对应项目实际使用的 FreeMarker 版本常量,以保护应用免受非完全向后兼容的改变影响。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@continew-plugin/continew-plugin-generator/src/main/java/top/continew/admin/generator/service/impl/GeneratorServiceImpl.java`
at line 312, 当前在构造 DefaultObjectWrapper 时使用了 Configuration.getVersion()(见
DefaultObjectWrapperBuilder 的构造调用),这会随运行时 FreeMarker 版本变化带来不确定行为;请改为使用固定的
FreeMarker 版本常量(例如 Configuration.VERSION_2_3_33 或项目实际使用的常量)作为
DefaultObjectWrapperBuilder 的构造参数,以保证向后兼容性并避免运行时行为改变。

@Charles7c Charles7c merged commit f6075ca into continew-org:dev Apr 3, 2026
3 of 4 checks passed
@luoqiz luoqiz deleted the fix-gen branch April 3, 2026 08:55
onekr-billy pushed a commit to onekr-billy/continew-admin that referenced this pull request May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants