<?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就业套餐课:https://edu.csdn.net/combo/detail/1230