有点复杂,要一次从数据库读取不少内容,关联两次取子集
类定义:
@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);