Skip to content

Fix parameter aliases in nested wrapper conditions - #7220

Merged
miemieYaho merged 7 commits into
baomidou:3.0from
wozhenbang2004:fix/nested-wrapper-param-alias
Oct 30, 2026
Merged

miemieYaho merged 7 commits into
baomidou:3.0from
wozhenbang2004:fix/nested-wrapper-param-alias

Conversation

@wozhenbang2004

Copy link
Copy Markdown
Contributor

Summary

Fix parameter-alias propagation when Java wrappers contain nested conditions or an existing lambda view.

MybatisMapperMethod changes the root wrapper alias to match a custom @Param, but nested wrappers can still generate #{ew.paramNameValuePairs...}. Binding a mapper parameter named filter then fails with Parameter 'ew' not found. Previously rendered nested conditions can also restore the old alias when a subsequent condition invalidates the root SQL cache.

Keep one shared alias holder across Java wrapper/lambda views, and recursively rewrite cached nested segments using the original alias. Preserve the wrapper nodes so consumers such as the optimistic-lock interceptor can still traverse them.

The change is scoped to root alias changes and Java wrapper views; it does not redesign Kotlin wrapper construction or child-local alias overrides. The diff contains one production file and four existing test files, with no workflow changes.

Reproduction

A mapper method accepting @Param("filter") QueryWrapper<String> wrapper and SQL using ${filter.customSqlSegment} fails to bind nested conditions such as:

new QueryWrapper<String>().eq("status", 1)
    .and(nested -> nested.eq("id", 2).or(deeper -> deeper.eq("id", 3)));

The root alias becomes filter, but the nested placeholders can remain under ew. The new mapper regression exercises alias conversion, XML SQL generation, and actual DefaultParameterHandler binding of all three parameters.

Validation

  • Add regressions for unrendered nesting, rendered nesting followed by appended conditions, mixed query/lambda nesting, and shared update/lambda SET and WHERE clauses.
  • The same isolated regression/control suite gives 68 passes and five failures with the original AbstractWrapper, and 73/73 passes with the fix, with zero skipped tests. It was rerun after the formatting-only correction.
  • The unchanged official Gradle Build workflow passed on JDK 17, 21, and 25 in the fork-local validation run, for head 214ee029b2c5057a388b31295853a3dd7913a692 against base c24d00c44ed25e3ba10de7ae71217447fefe2165. All three jobs passed both commands:
./gradlew spotlessCheck
./gradlew build -x :mybatis-plus-up:build -x :mybatis-plus-up:test

No extra module or test exclusions were added. The repository's existing default test-tag exclusions remain unchanged. This is the official build result, not a claim that the separate external-database/stress/build-metadata suites ran.

@miemieYaho
miemieYaho merged commit 0b0af8a into baomidou:3.0 Oct 30, 2026
3 checks passed
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.

2 participants