La Riba winded
The multi-table queries mybatis relationships between tables There are several: many many-to- one- to-many examples: the user and the order is many orders and many-user is a user can place multiple orders multiple orders belong to the same user and the ID number is the one a person can have only one ID number an ID card number can only belong to one person is many to many between teacher and student a student teacher may be more I taught a student teacher can pay more exception: if out each order, he can only belong to one user. So Mybatis put many to look into one. The multi-table queries mybatis: Example: the user account and a user may have multiple accounts an account can only belong to one user (s account may also belong to the same user) Step: 1 , the establishment of two tables: a user table, account table So that users have a one to many relationship between the table and the account table: the need to add foreign key in the account Table 2 , the establishment of two entity classes: classes and user entities account entity classes allows users to type and entity accounts can be reflected a the relationship between the number of 3 , the establishment of two profiles the user's profile account profile 4 , for configuration: when we query the user, the user can obtain account information contained in the same time when we check your account, you can get an account at the same time user information belongs example: users and roles a user can have multiple roles a role can give multiple users steps: 1 , the establishment of two tables: a user table, table role allows users and role tables have a many to many relationship. Need to use an intermediate table, the intermediate table comprising a respective main key, in the middle of the table is a foreign key. 2 , create two entity classes: class of user entities and roles entity classes allow the user entity classes and roles can be reflected many relationships each other contains a collection of reference 3 , the establishment of two profiles profile user role profiles 4 , for configuration: When we query the user, the user can get character information contained while the user when we query role, the role can be simultaneously conferred information