MyBatis multiple-to-one correlation query implementation
1. Defining Entities
When defining an entity, it is important to note that if two-way correlation is present, the property of both sides contains the object as a domain attribute.
It is important to note that the ToString () method is written so that only one party can output it, not the ToString () of both sides ,
This will form a recursive call, and the program will make an error and report a stack overflow.
Country entity Class
Minsiter entity class
2. Database Design
A) Country database
b) Minsiter database
3.DAO Layer Design
4.service Layer Design
5.impl Implementation Class
6.Controller Layer
7. most critical is the configuration of the mapping file,countrymapper.xml configuration file
It is worth notingthat in <resultMap> even if the field names and property names in result are the same, they must be written out because the framework is based on this <resultMap> encapsulates the object's. In addition, the use of <association> tags in the mapping file reflects the relationship between two entities, the meaning of two attributes:
Property: Specifies the associated attribute. In this case , it is the property name of the Country object .
Javatype: The type of the associated object property.
MyBatis Many-to-one correlation