EmployeeMapper.xml 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.sf.mapper.EmployeeMapper">
  6. <select id="getEmployeeinfo" parameterType="integer" resultType="employee">
  7. select * from employee where emp_id = #{empId}
  8. </select>
  9. <!--
  10. 一对多用 <collection>
  11. 多对一用 <association> javaType 是映射实体类的全类名
  12. resultMap="map2" <====> <resultMap id="map2"> 一一对应
  13. -->
  14. <resultMap id="map2" type="employee">
  15. <id column="emp_id" property="empId"></id>
  16. <result column="emp_name" property="empName"></result>
  17. <result column="salary" property="salary"></result>
  18. <association property="department" javaType="department">
  19. <id column="dept_id" property="deptId"></id>
  20. <result column="dept_name" property="deptName"></result>
  21. </association>
  22. </resultMap>
  23. <select id="getEmployeeinfoWithDepartment" parameterType="integer" resultMap="map2">
  24. select *
  25. from employee t1,
  26. department t2
  27. where t1.dept_id = t2.dept_id
  28. and t1.emp_id = #{empId};
  29. </select>
  30. </mapper>