1234567891011121314151617181920212223242526272829303132333435 |
- <?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.sf.mapper.EmployeeMapper">
- <select id="getEmployeeinfo" parameterType="integer" resultType="employee">
- select * from employee where emp_id = #{empId}
- </select>
- <!--
- 一对多用 <collection>
- 多对一用 <association> javaType 是映射实体类的全类名
- resultMap="map2" <====> <resultMap id="map2"> 一一对应
- -->
-
- <resultMap id="map2" type="employee">
- <id column="emp_id" property="empId"></id>
- <result column="emp_name" property="empName"></result>
- <result column="salary" property="salary"></result>
- <association property="department" javaType="department">
- <id column="dept_id" property="deptId"></id>
- <result column="dept_name" property="deptName"></result>
- </association>
- </resultMap>
-
- <select id="getEmployeeinfoWithDepartment" parameterType="integer" resultMap="map2">
- select *
- from employee t1,
- department t2
- where t1.dept_id = t2.dept_id
- and t1.emp_id = #{empId};
- </select>
- </mapper>
|