老师表 teacher
id | name | age |
---|---|---|
1 | 王老师 | 25 |
2 | 李老师 | 32 |
3 | 张老师 | 23 |
学生表 student
id | t_id | name | age |
---|---|---|---|
1 | 1 | 张敏 | 8 |
2 | 1 | 安仨 | 7 |
3 | 2 | 胡嗄 | 8 |
4 | 2 | 历海 | 8 |
5 | 3 | 萨德 | 9 |
<resultMap id="ResultMap" type="org.demo.Teacher">
<result column="id" property="id" />
<result column="name" property="name" />
<result column="age" property="age" />
<association property="student" columnPrefix="stu_" resultMap="studentResultMap"/>
</resultMap>
<resultMap id="studentResultMap" type="org.demo.Student">
<result column="id" property="id" />
<result column="name" property="name" />
<result column="age" property="age" />
</resultMap>
SELECT
tc.*,
st.id AS stu_id,
st.NAME AS stu_name
FROM
teacher tc
INNER JOIN student st ON tc.id = st.t_id
sql查询出有五条
用resultMap association 查出只有三条数据
teacher里面应该是个list,而不是个bean