1.出现的问题:查询出的结果错误,原本应该只有一的那端查询出了多条数据,映射错误
2.问题原因:查询结果id字段名重复
3.解决办法:改掉多的那端id名即可
代码如下:
mapper文件代码:
<resultMap id="BaseResultMap" type="com.sx.entity.PaperQuestions"> <id column="id" jdbcType="INTEGER" property="id" /> <result column="paper_id" jdbcType="VARCHAR" property="paperId" /> <result column="question_type" jdbcType="VARCHAR" property="questionType" /> <result column="question_grade" jdbcType="VARCHAR" property="questionGrade" /> <collection property="answerList" ofType="com.sx.entity.QuestionsAnswer" javaType="List"> <id column="aid" jdbcType="INTEGER" property="id" /> <result column="question_id" jdbcType="VARCHAR" property="questionId" /> </collection> </resultMap>
<select id="queryPaperQuestionsList" parameterType="java.util.Map" resultMap="ResultMapWithBLOBs"> select answer.id as aid,answer.question_id,questions.* from sx_paper_questions questions join sx_questions_answer answer on questions.id = answer.question_id </select>
entity代码:
private List<QuestionsAnswer> answerList = new ArrayList<>();
只是做个记录,防止下次遇到同样的问题