mybatis复杂查询
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.Dao.UserMapper">
<!--复杂查询-->
<!-- 查询所有学生-->
<select id="getAllStudentAndTeacher" resultMap="StudentTeacher">
select * from student
</select>
<resultMap id="StudentTeacher" type="com.pojo.User">
<result property="id" column="id"></result>
<result property="name" column="name"></result>
<result property="age" column="age"></result>
<association property="teacher" column="uid" javaType="com.pojo.teacher" select="getTeacher"></association>
</resultMap>
<!-- 查询对应的老师-->
<select id="getTeacher" resultType="com.pojo.teacher">
select * from teacher where id = #{uid}
</select>
</mapper>