一对多查询由于id导致的血案

<resultMap type="Paper" id="paperSingleQuestionMap">
		<id property="id" column="id"></id>
		<!-- 配置一对多的关系 -->
		<collection property="singleQuestions" ofType="SingleQuestion">
			<id property="id" column="id" javaType="int"></id>
			<result property="qsTitle" column="qs_title"/>
		</collection>
	</resultMap>
	
	<select id="findSingleQuestionByPaperId" parameterType="int" resultMap="paperSingleQuestionMap">
		SELECT * FROM paper p,single_question sq WHERE p.`id`=sq.`paper_id` AND p.`id`=#{pid}
	</select>

理想数据

在这里插入图片描述

实际数据

在这里插入图片描述

参考博客:mybatis查询一对多时只返回一条数据的问题

发布了45 篇原创文章 · 获赞 6 · 访问量 4858

猜你喜欢

转载自blog.csdn.net/weixin_45493345/article/details/104523995