deptDaoMapper.xml
部門對應員工(1對多的關系)
<resultMap type="com.hw.entity.Dept" id="deptinfo"><!-- 如果不用resultMap則不寫 --> <result column="did" property="did" /> <result column="dname" property="dname" /> <!-- mybatis中 1方配置多方 --> <collection property="per" ofType="com.hw.entity.Person"> <result column="pid" property="pid" /> <result column="pname" property="pname" /> <result column="psex" property="psex" /> <result column="skilled" property="skilled" /> <result column="degree" property="degree" /> <result column="jobtime" property="jobtime" javaType="java.sql.Date" jdbcType="DATE" /> <result column="resume" property="resume" /> <result column="filepath" property="filepath" /> </collection> </resultMap>
javabean中的屬性是集合set ,這時用collection
personDaoMapper.xml
員工對應部門(多對一的關系)
<resultMap type="com.hw.entity.Person" id="personinfo"><!-- 如果不用resultMap則不寫 --> <result column="pid" property="pid" /> <result column="pname" property="pname" /> <result column="psex" property="psex" /> <result column="skilled" property="skilled" /> <result column="degree" property="degree" /> <result column="jobtime" property="jobtime" javaType="java.sql.Date" jdbcType="DATE" /> <result column="resume" property="resume" /> <result column="filepath" property="filepath" /> <!--多對一的關系, property: 指的是屬性的值, javaType:指的是屬性的類型 --> <association property="dept" javaType="com.hw.entity.Dept"> <result column="did" property="did" /> <result column="dname" property="dname" /> </association> </resultMap>
javabean是類與類之間的關聯,這時用association
關聯(Association)關系是類與類之間的聯接,它使一個類知道另一個類的屬性和方法。關聯可以是雙向的,也可以是單向的。在Java語言中,關聯關系一般使用成員變量來實現。
作者:憤怒的_菜鳥
鏈接:https://www.jianshu.com/p/92efd20637ed
來源:簡書
著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請注明出處。