Skip to content

Conversation

@OxLeOx
Copy link

@OxLeOx OxLeOx commented Nov 18, 2025

Summary

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

Changes Made:

  1. 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 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 both javaClientGenerator.xhtml and table.xhtml documentation files
  4. How It Works:

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

Example Usage:

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

This will generate mapper interfaces like:

public interface UserMapper extends BaseMapper<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 at https://gittensor.io/

@OxLeOx
Copy link
Author

OxLeOx commented Nov 18, 2025

want your review @hazendaz

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.

Feature Request : Generics support in javaClientGenerator rootInterface

1 participant