myBatis如何将许多选择结果组合到一个实体中

时间:2016-12-11 15:27:19

标签: mybatis

我有一个实体:一个问题有很多答案。 使用JSTL方便地显示结果,我想将许多选择结果合并到一个实体;如下所示:

<!-- 根据节查找 -->
  <select id="selectDetailedBySectionId" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    q.id, q.question, q.type, q.tea_id,
    a.id as ans_id, a.item as ans_item, a.isTrue as ans_isTrue
    from questions q, answers a
    where q.sec_id = #{id} and q.id = a.que_id
  </select>

我给了一个选择,它返回到4个结果。如果我这样,那么frontPage是这样的:

enter image description here

所以有一种方法可以将这些实体组合成一个实体。

1 个答案:

答案 0 :(得分:0)

据我所知,您需要一个结果实体,包括:1 question =&gt; N个答案的集合。

您必须使用Mybatis集合映射see an example here