一对多的三种方式和多对一
Posted donghongbo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一对多的三种方式和多对一相关的知识,希望对你有一定的参考价值。
<!-- 对象级联 --> <resultMap type="Emp" id="emplist1"> <id property="empno" column="EMPNO"/> <result property="ename" column="ENAME"/> <result property="job" column="JOB"/> <result property="mgr" column="MGR"/> <result property="hiredate" column="HIREDATE"/> <result property="sal" column="SAL"/> <result property="comm" column="COMM"/> <result property="deptno" column="DEPTNO"/> <result property="sex" column="SEX"/> <result property="dept.dno" column="DNO"/> <result property="dept.dname" column="DNAME"/> <result property="dept.loc" column="LOC"/> </resultMap>
<!-- 关联 --> <resultMap type="Emp" id="emplist2"> <id property="empno" column="EMPNO"/> <result property="ename" column="ENAME"/> <result property="job" column="JOB"/> <result property="mgr" column="MGR"/> <result property="hiredate" column="HIREDATE"/> <result property="sal" column="SAL"/> <result property="comm" column="COMM"/> <result property="deptno" column="DEPTNO"/> <result property="sex" column="SEX"/> <association property="dept" resultMap="deptlist"></association> </resultMap> <resultMap type="Dept" id="deptlist"> <result property="dno" column="DNO"/> <result property="dname" column="DNAME"/> <result property="loc" column="LOC"/> </resultMap>
<!-- 关联查询 -->· <!-- <resultMap type="Emp" id="emplist3"> <association property="dept" column="DEPTNO" select="mapper.DeptMapper.selectDept"></association> </resultMap> <select id="selectAllEmp" resultMap="emplist3"> select * from p_emp e </select> -->
多对一
<resultMap type="Dept" id="deptSelect"> <id property="dno" column="dno"/> <collection property="emp" column="dno" select="mapper.EmpMapper.selectOneEmp"/> </resultMap> <select id="selectDept" parameterType="Integer" resultMap="deptSelect"> select * from p_dept d where d.dno=#{dno} </select>
以上是关于一对多的三种方式和多对一的主要内容,如果未能解决你的问题,请参考以下文章