Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Generic Support for javaClientGenerator#1373

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
OxLeOx wants to merge1 commit intomybatis:master
base:master
Choose a base branch
Loading
fromOxLeOx:feat/generic-support-for-javaClientGenerator

Conversation

@OxLeOx
Copy link

Summary

Implemented generic type support for therootInterface property in MyBatis Generator, addressing issue#1346.

Changes Made:

  1. Added utility method inAbstractJavaClientGenerator:

    • processRootInterfaceWithGenerics(): Processes the rootInterface string and replaces generic placeholders (e.g.,<T>,<T extends Entity>) with the actual record type from the introspected table

    • isGenericPlaceholder(): Detects if the generic content is a placeholder (single uppercase letter like T, E, K, V, optionally with "extends" or "super" clause)

  2. Updated all three Java client generators:

    • JavaMapperGenerator

    • SimpleJavaClientGenerator

    • DynamicSqlMapperGenerator

  3. Updated documentation:

    • Added "Generic Type Support" section to bothjavaClientGenerator.xhtml andtable.xhtml documentation files
  4. How It Works:

    • If you specifyrootInterface="BaseMapper<T>", it becomesBaseMapper<com.example.User> for a User table
    • If you specifyrootInterface="BaseMapper<T extends Entity>", it becomesBaseMapper<com.example.User>
    • If you specifyrootInterface="BaseMapper" (no generics), it remains unchanged (backward compatible)
    • If you specifyrootInterface="BaseMapper<com.example.User>" (fully qualified), it's used as-is

Example Usage:

<javaClientGeneratortargetPackage="com.example.mapper"targetProject="src/main/java"type="XMLMAPPER">    <propertyname="rootInterface"value="com.mycompany.BaseMapper&lt;T&gt;"/></javaClientGenerator>

This will generate mapper interfaces like:

publicinterfaceUserMapperextendsBaseMapper<User> {// ...}

Resolves

Closes#1346 - Feature Request : Generics support in javaClientGenerator rootInterface


The implementation is backward compatible and passes all linter checks.
Ready for testing and review.

Contribution by Gittensor, learn more athttps://gittensor.io/

@OxLeOx
Copy link
Author

want your review@hazendaz

@OxLeOx
Copy link
Author

@hazendaz

@jeffgbutler
Copy link
Member

I will take a look at this, but it might take me a few days to get to it.

@jeffgbutler
Copy link
Member

jeffgbutler commentedDec 2, 2025
edited
Loading

Thanks for the contribution - and thanks for updating the docs too! But there's a much easier way. There is already well-tested code in the library that can do all the parsing.

I also don't think we should rely on assumptions to determine if the type substitution should occur. I prefer to make it explicit with a new property like the following:

<propertyname="injectGeneratedTypeIntoBaseInterface"value="true" />

Then you could write a function like the following:

privateFullyQualifiedJavaTypeinjectGeneratedType(StringbaseInterfaceType,StringinjectedType,booleaninject) {FullyQualifiedJavaTypebaseInterface =newFullyQualifiedJavaType(baseInterfaceType);if (baseInterface.getTypeArguments().size() ==1 &&inject) {FullyQualifiedJavaTypeanswer =newFullyQualifiedJavaType(baseInterface.getFullyQualifiedNameWithoutTypeParameters());answer.addTypeArgument(newFullyQualifiedJavaType(newFullyQualifiedJavaType(injectedType).getShortName()));returnanswer;    }else {returnbaseInterface;    }}

Lastly, I'd like to see some tests added for this new function.

@jeffgbutlerjeffgbutler self-requested a reviewDecember 2, 2025 20:11
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@jeffgbutlerjeffgbutlerAwaiting requested review from jeffgbutler

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Feature Request : Generics support in javaClientGenerator rootInterface

2 participants

@OxLeOx@jeffgbutler

[8]ページ先頭

©2009-2025 Movatter.jp