Search code examples
javamybatisspring-mybatismybatis-generator

Mybatis generator xml configuration. Set join between tables


I have three tables:

  1. table ONE pk:ONE.ID
  2. table TWO fk:TWO.ID with ONE.ID pk:TWO.ID TWO.FIELD
  3. table THREE fk:TWO.ID with THREE.ID and TWO.FIELD=THREE.FIELD

Is it possible to set the join in the xml configuration, and let mybatis to generate the classes and methods with the join?

Thanks.


Solution

  • MyBatis Generator does not generate code for joins.

    However, the "MyBatis Dynamic SQL" library has support for joins. You could use MyBatis Generator to generate the basic CRUD operations for the tables, then add the joins yourself. Just set <context targetRuntime="MyBatis3DynamicSql">

    There is information on this page regarding joins in the library: http://www.mybatis.org/mybatis-dynamic-sql/docs/select.html