mybatis association 如何在一对多查询出多的数据?

老师表 teacher

idnameage
1王老师25
2李老师32
3张老师23

学生表 student

idt_idnameage
11张敏8
21安仨7
32胡嗄8
42历海8
53萨德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 查出只有三条数据

阅读 1.8k
1 个回答

teacher里面应该是个list,而不是个bean

推荐问题