實訓--經驗總結5
阿新 • • 發佈:2018-07-11
dao part dep 裏的 name collect .org lec .com
一對一,和一對多 。 mybatis寫法
一對多:
DepEmpInfoDao.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.icss.dao.DepEmpInfoDao"> <select id="getDepEmpByDepId" parameterType="int" resultMap="DepMap"> select * from department d INNER JOIN employee e on e.d_id =e.d_id and e.d_id = #{id} </select> <resultMap type="Dep" id="DepMap"> <id column="d_id" property="d_id" /> <result column="dname" property="d_name" /> <!-- 裝配一個集合 collection 申明集合中的元素類型ofType=--> <!-- collection 一對多 註意;ofType 一定要指明這個集合裏的成員類型,不然報nullPorionException--> <collection property="employee" ofType="Emp"> <id column="e_id" property="e_id" /> <result column="empName" property="e_name" /> <result column="job" property="e_job" /> <result column="sal" property="sal" /> <!-- <result column="d_id" property="d_id" /> --> </collection> </resultMap> </mapper>
實訓--經驗總結5