- Notifications
You must be signed in to change notification settings - Fork2.5k
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
base:master
Are you sure you want to change the base?
Generic Support for javaClientGenerator#1373
Uh oh!
There was an error while loading.Please reload this page.
Conversation
OxLeOx commentedNov 18, 2025
want your review@hazendaz |
OxLeOx commentedDec 2, 2025
jeffgbutler commentedDec 2, 2025
I will take a look at this, but it might take me a few days to get to it. |
jeffgbutler commentedDec 2, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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. |
Summary
Implemented generic type support for the
rootInterfaceproperty in MyBatis Generator, addressing issue#1346.Changes Made:
Added utility method in
AbstractJavaClientGenerator:processRootInterfaceWithGenerics(): Processes the rootInterface string and replaces generic placeholders (e.g.,<T>,<T extends Entity>) with the actual record type from the introspected tableisGenericPlaceholder(): Detects if the generic content is a placeholder (single uppercase letter like T, E, K, V, optionally with "extends" or "super" clause)Updated all three Java client generators:
JavaMapperGeneratorSimpleJavaClientGeneratorDynamicSqlMapperGeneratorUpdated documentation:
javaClientGenerator.xhtmlandtable.xhtmldocumentation filesHow It Works:
rootInterface="BaseMapper<T>", it becomesBaseMapper<com.example.User>for a User tablerootInterface="BaseMapper<T extends Entity>", it becomesBaseMapper<com.example.User>rootInterface="BaseMapper"(no generics), it remains unchanged (backward compatible)rootInterface="BaseMapper<com.example.User>"(fully qualified), it's used as-isExample Usage:
This will generate mapper interfaces like:
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/