mybatisplus关联查询

@Data
public class MyExamVo implements Serializable {
    private static final long serialVersionUID = 1L;
	private ExamStu exam;
     private BatchNum pc;

    private Named name;


}

mapper xml

<select id="getMyExamList" resultMap="myExamMap">
        select k.*,p.st_name_id from xg_ks_stu k
        left join xg_ks_pc p
        on k.pc_id =p.id
        where
        k.xs_id  = #{xsId}
    </select>

    <resultMap id="myExamMap" type="org.stu.exam.vo.MyExamVo">
	    <association property="exam"  resultMap="examMap"></association>
        <association property="pc" column="pc_id"  select="selBatch"></association>
        <association property="name" column="st_name_id"  select="selName"></association>
    </resultMap>
	 <resultMap id="examMap" type="org.jeecg.modules.stu.exam.entity.ExamStu">
        <id property="id" column="id"></id>
        <result property="pcId" column="pc_id"></result>
        <result property="xsId" column="xs_id"></result>
        <result property="beginTime" column="begin_time"></result>
        <result property="subTime" column="sub_time"></result>
        <result property="score" column="score"></result>
    </resultMap>
    <resultMap id="batchMap" type="org.stu.exam.entity.BatchNum"></resultMap>
    <resultMap id="nameMap" type="org.stu.exam.entity.Named"></resultMap>

    <select id="selBatch" resultMap="batchMap">
        select * from xg_ks_pc where id=#{id}
    </select>
    <select id="selName" resultMap="nameMap">
        select * from xg_ks_name where id=#{id}
    </select>

mapper类

 IPage<MyExamVo> getMyExamList(Page page, @Param("xsId") String xsId);

impl类

 @Override
    public IPage<MyExamVo> getMyExam(Page page, String xsId){
        return batchNumMapper.getMyExamList(page,xsId);
    }

先是一个关联查询,从记录结果中用 pc_id 和 st_name_id 传参 分别关联查询,得到两个对象,作为属性封装为一个对象,examMap 定义了一个映射,主查询中字典与类ExamStu 中的属性进行对应

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值