再记mybatisplus,备忘

本文介绍了一个复杂的MyBatis关联查询案例,通过多个XML映射文件实现了一次性从数据库获取完整的考试题目信息,包括题目基本信息、选项及图片等。此方案有效地减少了数据库交互次数,提高了查询效率。

有点复杂,要一次从数据库读取不少内容,关联两次取子集

类定义:

@Data
public class ExamTitle implements Serializable {
    private static final long serialVersionUID = 1L;
      private Named named;
   private List<TitlePage> titleList;
}

@Data
public class TitlePage {
	private java.lang.String id;
	private java.lang.String title;
	private List<Items> itemsList;
	private List<TitlePic> titlePicList;
}

@Data
public class Items implements Serializable {
    private static final long serialVersionUID = 1L;
	private java.lang.String id;
	private java.lang.String titleId;
	private java.lang.String type;
	private java.lang.String content;
	private java.lang.String pic;
}
@Data
public class TitlePic implements Serializable {
    private static final long serialVersionUID = 1L;
	private java.lang.String id;
	private java.lang.String titleId;
	private java.lang.String pic;
}

xml内容:

 <select id="getExamTitle" resultMap="examTitleMap">
      select * from xg_ks_name where id=#{id}
    </select>
    <resultMap id="examTitleMap" type="org.jeecg.modules.stu.exam.vo.ExamTitle">
        <association property="named" resultMap="nameMap"></association>
        <collection property="titleList" column="id" select="selTitle"></collection>
    </resultMap>
    <resultMap id="nameMap" type="org.jeecg.modules.stu.exam.entity.Named">
        <id property="id" column="id"></id>
        <result property="type" column="type"></result>
        <result property="title" column="title"></result>
        <result property="score" column="score"></result>
    </resultMap>

    <resultMap id="titleMap" type="org.jeecg.modules.stu.tiku.vo.TitlePage">
        <id property="id" column="id"></id>
        <result property="libId" column="lib_id"></result>
        <result property="title" column="title"></result>
        <result property="type" column="type"></result>
        <result property="stemType" column="stem_type"></result>
        <result property="score" column="score"></result>
        <result property="diffLevel" column="diff_level"></result>
        <result property="gradeId" column="grade_id"></result>
        <collection property="itemsList" column="id" select="selItem"></collection>
        <collection property="titlePicList" column="id" select="selTitlePic"></collection>
    </resultMap>

    <select id="selItem" resultType="org.jeecg.modules.stu.tiku.entity.Items">
        select * from xg_tk_items where title_id=#{id}
    </select>
    <select id="selTitlePic" resultType="org.jeecg.modules.stu.tiku.entity.TitlePic">
       select * from xg_tk_title_pic where title_id=#{id}
    </select>
    <select id="selTitle" resultMap="titleMap">
    select b.* from xg_ks_name_item a
    left join xg_tk_title b
    on a.title_id=b.id
    where a.name_id=#{id}
  </select>

mapper:

ExamTitle getExamTitle(@Param("id") String id);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值