只需在一对多的 “一” Model中定义一个list集合:

public class SelectQuestion{

    // 主键ID
    private Integer id;

    private String name;
    //选项列表
    private List<SelectOption> optionList;
//省略了getter和setter方法

然后在一对多的 “一” Mapper定义

<resultMap id="BaseResultMap" type="com.model.SelectQuestion">
        <id column="id" property="id"/>
        <result column="task_id" property="taskId"/>
        <result column="select_content" property="selectContent"/>
        <collection property="optionList" column="id" ofType="com.model.SelectOption">
            <id property="id" column="option_id"/>
            <result property="taskId" column="task_id"/>
            <result property="selectId" column="select_id"/>
            <result property="optionFlag" column="option_flag"/>
            <result property="optionContent" column="option_content"/>
        </collection>
    </resultMap>

<select id="findListSelectQuestionNoAnswer" resultMap="BaseResultMap">
        SELECT a.*,b.id AS option_id,b.select_id,b.option_flag,b.option_content FROM test_select_question AS a
        LEFT JOIN test_select_option b ON a.id=b.select_id
        <include refid="findByQoCondition"></include>
    </select>

注意下,如果2个表的查询,字段相同,请设置别名。

至于mapper.java 就和普通的单表查询一样写了

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-10
  • 2021-07-06
  • 2021-07-10
  • 2021-10-13
  • 2021-11-02
  • 2021-04-03
猜你喜欢
  • 2022-01-27
  • 2021-08-02
  • 2021-07-17
  • 2021-06-27
  • 2022-02-07
相关资源
相似解决方案