使用iBatis联查DEPT、EMP两张表时
采用如下结构
<resultMap id="find_departmentMap" class="com.dto.DepartmentDTO"> <result property="deptNO" column='deptNO'/> <result property="dName" column='dName'/> <result property="loc" column='loc'/> <result property="employeeList" column='{deptNO=depNO}' select="comSqlMap.findEmployee" /> </resultMap> <select id="findDepartment" parameterClass="java.util.HashMap" resultClass="find_departmentMap"> SELECT DEPTNO, DNAME, LOC FROM DEPT WHERE DEPTNO = #deptNO# AND DNAME = #dName# </select> <select id="findEmployee" parameterClass="java.lang.String" resultClass="com.dto.EmployeeDTO"> SELECT EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO FROM EMP WHERE DEPTNO = #deptNO# </select>
程序报错:“employeeList" 列名无效
处理方法:把“findEmployee”的select的parameterClass属性值改为java.util.HashMap,如下所示
<select id="findEmployee" parameterClass="java.util.HashMap" resultClass="com.dto.EmployeeDTO"> SELECT EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO FROM EMP WHERE DEPTNO = #deptNO# </select>