天天看點

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類

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