<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><!-- 命名空間 xml與dao的鏈接 --><mapper namespace="com.aaa.dao.EmpMapper"> <resultMap type="emp" id="empMap"> <id column="empno" property="empno"/> <association column="deptno" property="dept" javaType="dept"> <id column="deptno" property="deptno"/> </association> </resultMap> <select id="selectManytoOne" parameterType="int" resultMap="empMap"> select e.empno,e.ename,e.job,e.mgr,e.hiredate,e.sal,e.comm, e.deptno,d.dname,d.loc from emp e left join dept d on e.deptno=d.deptno where d.deptno=#{deptno} </select></mapper>
緣由在於個別開發者或同窗沒有寫主表的empno, 會出現查詢結果有數據,可是結果只有一條的狀況。java