MyBatis configuration is made of 3 beans 

Execution sequence at runtime :

  1. The Repositories/Dao objects autowire the custom or generated mapper interface. 
  2. They repositories invoke a method on the mapper interface. This is a synchronous and waits for a response before returning from method call.
  3. MyBatis invokes the sql statement in the mapper xml in the database configured 
  4. MyBatis returns a model or list of models to the interfaces which returns the reponse to calling dao/repository

Note:


The return type is the determined by the Mapper interface. If you define a mapper to return a list, MyBatis will return a list of the models or an empty list if the underlying query return no records. If a single model object is defined as the return type a single object will be returned or null if the underlying database table returns no record.

Mybatis has a rowbounds plugin for controlling the number of records returned. OpenSRP does not use the plugin as if fetches all records and then limits the rows returned after fetching and then returns the filtered list . OpenSRP uses customMappers to define a seachMany method that passes a row limit parameter to control the number of rows fetched on the database and and offset parameter that controls the offset/starting position to query the data. 

You can use example classes to construct complex queries or you can implement custom methods using the mapper interfaces and the mapper xml where you can define the actual sql statements

Refer to the documentation at  http://www.mybatis.org/mybatis-3.