记一次使用mybatis一对多出现的问题

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<>();

 只是做个记录,防止下次遇到同样的问题

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值