Skip to content

Conversation

@CodeCasterX
Copy link
Member

🔗 相关问题 / Related Issue

Issue 链接 / Issue Link: #304 👈👈

  • 我已经创建了相关 Issue 并进行了讨论 / I have created and discussed the related issue
  • 这是一个微小的修改(如错别字),不需要 Issue / This is a trivial change (like typo fix) that doesn't need an issue

📋 变更类型 / Type of Change

  • 🐛 Bug 修复 / Bug fix (non-breaking change which fixes an issue)
  • ✨ 新功能 / New feature (non-breaking change which adds functionality)
  • 💥 破坏性变更 / Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 文档更新 / Documentation update
  • 🔧 重构 / Refactoring (no functional changes)
  • ⚡ 性能优化 / Performance improvement
  • 📦 依赖升级 / Dependency upgrade (update dependencies to newer versions)
  • 🚀 功能增强 / Feature enhancement (improve existing functionality without breaking changes)
  • 🧹 代码清理 / Code cleanup

📝 变更目的 / Purpose of the Change

增强 StringUtils.format 方法的灵活性,支持多种缺失参数处理策略,解决实际开发中处理模板字符串的痛点。

主要改进:

  1. 统一API设计: 将严格性和缺失参数策略融合到单一的 ParameterizationMode 枚举中
  2. 更好的实用性: 支持日志模板、配置文件、邮件模板等常见场景
  3. 向后兼容: 所有现有API保持不变,不影响现有代码
  4. 易于使用: 提供便捷方法,常用场景一行代码解决

解决的问题:

  • 日志模板缺失参数希望使用空字符串而非抛异常
  • 配置文件模板缺失参数希望使用统一默认值
  • 混合格式文本(如包含JSON的YAML)希望保持占位符可见性
  • 避免传递多个参数使API复杂化

📋 主要变更 / Brief Changelog

  • ✨ 新增 ParameterizationMode 枚举,包含5种格式化模式
  • ✨ 新增 MissingParameterBehavior 枚举,定义4种缺失参数处理策略
  • 🔧 重构 DefaultParameterizedString 支持新的参数处理逻辑
  • ✨ 新增便捷方法:formatLenientformatLenientWithDefaultformatKeepPlaceholder
  • 🧪 新增全面的单元测试,覆盖所有新功能和实际场景
  • 📚 更新JavaDoc文档和使用示例

🧪 验证变更 / Verifying this Change

测试步骤 / Test Steps

  1. 所有单元测试运行成功。

测试覆盖 / Test Coverage

  • 我已经添加了单元测试 / I have added unit tests
  • 所有现有测试都通过 / All existing tests pass
  • 我已经进行了手动测试 / I have performed manual testing

📸 截图 / Screenshots

✅ 贡献者检查清单 / Contributor Checklist

请确保你的 Pull Request 符合以下要求 / Please ensure your Pull Request meets the following requirements:

基本要求 / Basic Requirements:

  • 确保有 GitHub Issue 对应这个变更(微小变更如错别字除外)/ Make sure there is a Github issue filed for the change (trivial changes like typos excluded)
  • 你的 Pull Request 只解决一个 Issue,没有包含其他不相关的变更 / Your PR addresses just this issue, without pulling in other changes - one PR resolves one issue
  • PR 中的每个 commit 都有有意义的主题行和描述 / Each commit in the PR has a meaningful subject line and body

代码质量 / Code Quality:

  • 我的代码遵循项目的代码规范 / My code follows the project's coding standards
  • 我已经进行了自我代码审查 / I have performed a self-review of my code
  • 我已经为复杂的代码添加了必要的注释 / I have commented my code, particularly in hard-to-understand areas

测试要求 / Testing Requirements:

  • 我已经编写了必要的单元测试来验证逻辑正确性 / I have written necessary unit-tests to verify the logic correction
  • 当存在跨模块依赖时,我尽量使用了 mock / I have used mocks when cross-module dependencies exist
  • 基础检查通过:mvn -B clean package -Dmaven.test.skip=true,elsa README 中的编译检查 / Basic checks pass
  • 单元测试通过:mvn clean install / Unit tests pass

文档和兼容性 / Documentation and Compatibility:

  • 我已经更新了相应的文档 / I have made corresponding changes to the documentation
  • 如果有破坏性变更,我已经在 PR 描述中详细说明 / If there are breaking changes, I have documented them in detail
  • 我已经考虑了向后兼容性 / I have considered backward compatibility

📋 附加信息 / Additional Notes

设计亮点:

  1. 零破坏性: 所有现有API保持不变,现有代码无需修改
  2. 易于扩展: 新增模式只需在枚举中添加,符合开闭原则
  3. 类型安全: 通过枚举避免魔法值,编译时检查错误
  4. 实用导向: 基于真实开发场景设计,解决实际痛点

后续计划:

  • 可考虑在配置文件中支持模式选择
  • 可能需要根据用户反馈优化默认行为
  • 考虑添加更多便捷方法

审查者注意事项 / Reviewer Notes:

请重点关注:

  1. 新增的 ParameterizationMode 枚举设计是否合理
  2. 向后兼容性是否得到保证
  3. 测试用例是否覆盖了所有关键场景
  4. API设计是否符合项目整体风格

@CodeCasterX CodeCasterX added this to the 3.5.3 milestone Sep 23, 2025
@CodeCasterX CodeCasterX self-assigned this Sep 23, 2025
@CodeCasterX CodeCasterX added type: enhancement A general enhancement in: fit Issues in FIT modules labels Sep 23, 2025
@CodeCasterX CodeCasterX linked an issue Sep 23, 2025 that may be closed by this pull request
4 tasks
@CodeCasterX CodeCasterX merged commit b8ac984 into 3.5.x Sep 23, 2025
6 checks passed
@CodeCasterX CodeCasterX deleted the fit-enhancement-format branch September 23, 2025 13:05
surpercodehang pushed a commit to surpercodehang/fit-framework that referenced this pull request Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: fit Issues in FIT modules type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

格式化字符串方法需要更灵活的处理策略

3 participants