Following sample domain model
There will be User and each User may have a Blog and each Blog can contain zero or maore posts.
The Databse structure of the three table are as follows:
Here I am going to explain how to fetch and map -has One and One-To-Many result mappings.
In mybatis-config.xml,configure type aliases for beans.
*-has-One Result Mapping:
In UserMapper.xml, configure sql queries and result maps as follows:
In JUnit Test, write a method to test the association loading.
One-To-Many Results Mapping:
In BlogMapper.xml configure Blog to Posts relationship as follows:
In JUnit Test, write a test method to test blog-to-posts relationship mapping.