-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
修复了动态sqlSource不能自动映射的问题。 #933
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.3.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -33,9 +33,9 @@ | |||||
| import org.apache.ibatis.logging.LogFactory; | ||||||
| import org.apache.ibatis.mapping.MappedStatement; | ||||||
| import org.apache.ibatis.mapping.ResultMap; | ||||||
| import org.apache.ibatis.mapping.ResultMapping; | ||||||
| import org.apache.ibatis.mapping.SqlCommandType; | ||||||
| import org.apache.ibatis.reflection.MetaObject; | ||||||
| import org.apache.ibatis.scripting.defaults.RawSqlSource; | ||||||
| import org.apache.ibatis.session.Configuration; | ||||||
| import tk.mybatis.mapper.MapperException; | ||||||
| import tk.mybatis.mapper.annotation.RegisterMapper; | ||||||
|
|
@@ -303,11 +303,27 @@ public void processMappedStatement(MappedStatement ms) { | |||||
| setSqlSource(ms, mapperTemplate); | ||||||
| } | ||||||
|
|
||||||
| // 如果是原生mybatisSqlSource的查询,添加ResultMap | ||||||
| if (ms.getSqlSource() instanceof RawSqlSource | ||||||
| && ms.getSqlCommandType() == SqlCommandType.SELECT) { | ||||||
| if (ms.getResultMaps() != null && !ms.getResultMaps().isEmpty()) { | ||||||
| setRawSqlSourceMapper(ms); | ||||||
| // 如果没有resultMaps, 有则设置一个默认的resultMaps | ||||||
|
||||||
| // 如果没有resultMaps, 有则设置一个默认的resultMaps | |
| // 对于 SELECT 语句,如果已有 resultMaps 中存在仅指定 type 而未定义 mappings 的条目,则根据实体的 @Table 元数据生成并替换为默认的 ResultMap |
Copilot
AI
Feb 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里在循环内每次替换一个 ResultMap 都会重新构建 MetaObject 并多次 setValue("resultMaps")。建议用一个 changed 标记:先在循环里只更新 modifiableResultMaps,循环结束后(且仅当发生替换时)再一次性把新的不可变 List 回写到 ms,避免重复反射写入并让逻辑更清晰。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
测试用的 userAssert() 现在只断言 uname/age/createTime 非空,移除了之前对 email 的断言,导致无法验证本次修复的核心行为(resultType/动态 SQL 下是否正确应用实体的 ResultMap,以及 @transient 字段是否应被映射)。建议针对不同查询分别断言 email 应为 null(resultType/自动映射走实体 ResultMap)或非 null(显式 BaseResultMap),以避免回归。