Mybatis多对一的处理
多个学生对应一个老师
对于学生来说:关联一个老师 对象
1.建表:
注意两张表之间的主外键的关系
2.测试环境的搭建
- 导包
- mybatis核心配置文件
- mybatis工具类
- 实体类
- dao层接口
- mapper配置文件
- 测试
3.导包
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>mybatisA</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>mybatis1</module>
<module>mybatis2</module>
<module>mybatis3</module>
<module>mybatis4</module>
</modules>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<d