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.7k
1 个回答

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

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题