目录
多对一:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--namespace=绑定要给对应的Dao/mapper接口-->
<mapper namespace="com.gao.dao.StudentMapper">
<!--多对一处理-->
<!--
按照查询嵌套处理
思路:
1.查询所有的学生信息
2.根据查询出来的学生的tid, 寻找对应的老师
-->
<select id="getStudent" resultMap="StudentTeacher">
select * from student
</select>
<resultMap id="StudentTeacher" type="com.gao.pojo.Student">
<result property="id" column="id"></result>
<result property="name" column="name"></result>
<!--复杂的属性,我们需要单独处理,对象association 集合:collection
javaType 指定属性的类型
集合中的泛型信息,使用ofType获取
-->
<association property="teacher" column="tid" javaType="com.gao.pojo.Teacher" select="getTeacher"></association>
</resultMap>
<select id="getTeacher" resultType="com.gao.pojo.Teacher">
select * from teacher where id = #{tid};
</select>
<!--===============================