feat(generator): add table field meta info customizer#7041
Open
smf-h wants to merge 1 commit intobaomidou:3.0from
Open
feat(generator): add table field meta info customizer#7041smf-h wants to merge 1 commit intobaomidou:3.0from
smf-h wants to merge 1 commit intobaomidou:3.0from
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
变更说明
为
mybatis-plus-generator增加一个小范围、向后兼容的扩展点,允许用户在字段初始类型转换完成后、模板渲染前,对最终字段元信息进行自定义调整。背景
当前
ITypeConvertHandler主要负责类型转换逻辑。但是在类型转换完成后,到模板真正消费字段信息之间,缺少一个统一的后置处理入口。
这会让一些场景不太容易优雅处理,例如:
jdbcType或typeName本次改动
本 PR 新增一个扩展接口:
ITableFieldMetaInfoCustomizer并通过
Entity.Builder暴露配置入口:addTableFieldMetaInfoCustomizers(ITableFieldMetaInfoCustomizer...)addTableFieldMetaInfoCustomizers(List<ITableFieldMetaInfoCustomizer>)该扩展点会在以下两条查询链路中执行:
DefaultQuerySQLQuery同时,为了支持后置调整,
TableField.MetaInfo增加了部分 setter 方法,用于修改可变元信息字段。使用示例
兼容性说明
mybatis-plus-generator测试情况
已补充以下测试:
设计考虑
相比继续增加更多单点配置项,这种字段元信息后置扩展点更通用,也更容易复用,适用于后续类似场景,例如:
本次实现尽量保持改动面小,并避免修改现有默认生成行为。
Related to #7037