Zero, Preface This article is used to study one-to-many, many-to-one, and many-to-many relationships between tables and objects. Two methods of xml file configuration and annotation configuration were studied Super complete~ The entities used for research are students, teachers, courses Note: The relationship between students and teachers should be many-to-many. This article uses many-to-one, that is, […]
Tag: many-to-one
Mybatis implements multi-table query (one-to-many, many-to-one)
Explanation of many-to-one and one-to-many relationships: taking multiple students to one teacher as an example 1. Regarding students: Use the key “association” association to associate multiple students with one teacher ———–many-to-one 2. For teachers: Use the keyword “collection”, that is, a teacher has many students (collection)———one-to-many 1. Create database create table teacher( id int not […]
Mybatis many-to-one and one-to-many queries
Article directory Detailed explanation of Mybatis many-to-one and one-to-many query database need Mybatis code Notice Mybatis many-to-one and one-to-many query details Database Employee table t_emp Department table t_dept CREATE TABLE `t_emp` ( `emp_id` int NOT NULL AUTO_INCREMENT, `emp_name` varchar(25) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL, `age` int DEFAULT NULL, `gender` varchar(25) CHARACTER SET utf8 […]
MyBatis custom mapping resultMap, processing one-to-many, many-to-one
1. Custom mapping resultMap Review: The query tag select must set the attribute resultType or resultMap, which is used to set the mapping relationship between the entity class and the database table resultType: automatic mapping, used when the attribute name is consistent with the field name in the table (or the underscore is set to […]
Interpretation of mybatis many-to-one and one-to-many query data processing
Directory overview Preparation many to one eliciting the problem Cascading Attribute Mapping Processing association processing step by step query one-to-many eliciting the problem collection processing step by step query Interpretation of lazy loading What is lazy loading? How to enable lazy loading in mybatis? Overview The one-to-many and many-to-one of MyBatis are mainly the use […]
Many-to-one (association), one-to-many (collection)
1. Many-to-one processing Many-to-one understanding: Multiple students correspond to one teacher For the students, it is a many-to-one phenomenon, that is, connect a teacher from the students! 1.1, database design CREATE TABLE `teacher` ( `id` INT(10) NOT NULL, `name` VARCHAR(30) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=INNODB DEFAULT CHARSET=utf8 INSERT INTO teacher(`id`, `name`) VALUES (1, […]
Hibernate framework [4] – basic mapping – many-to-one and one-to-many mapping
Series article directory Hibernate framework [3] – basic mapping – one-to-one mapping Basic mapping – many-to-one and one-to-many mapping Series Article Directory foreword 1. What is many-to-one mapping? 1. Case: Now there are two entities, User entity and Group, where multiple Users belong to a Group, showing a many-to-one relationship. ①. Entity structure ②. XML […]
Springboot Episode 16: One-to-many, many-to-one, SQL cache
create table teacher ( id int(10) not null, name varchar(30) default null, primary key (id) ) engine = innodb default charset = utf8 insert into teacher (id, name) values (1, ‘jeskson’); create table student ( id int(10) not null, name varchar(30) default null, tid int(10) default null, primary key (id) key `fktid` (`tid`), constraint `fktid` […]
MyBatis association mapping (many-to-one, many-to-many)
Many-to-one query 3.1 Environment Configuration Orders.java add attribute User package com.biem.pojo; import lombok.*; @Getter @Setter @NoArgsConstructor @AllArgsConstructor @ToString public class Orders {<!– –> private Integer id; private String number; private Integer userId; private Users users; } 3.2 Solutions 3.2.1 Nested query method 3.2.1.1 UsersMapper.java added public Users getUsersById(Integer id); 3.2.1.2 Add OrdersMapper.java public List<Orders> getOrders1(Integer […]
Easy to understand Mybatis many-to-one, one-to-many
Environment build First import the coordinates in maven, including, mybatis, jdbc, druid connection pool, log4j log, lombok to quickly generate pojo <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.4.6</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13</version> <scope>test</scope> </dependency> <!– MySql driver –> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.47</version> </dependency> <!– druid Ali’s database connection pool –> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.10</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> […]