MyBatis Many-to-one correlation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.