1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?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.DepartmentMapper">
- <!-- 二级缓存-->
- <!-- <cache-->
- <!-- eviction="FIFO"-->
- <!-- flushInterval="60000"-->
- <!-- size="512"-->
- <!-- readOnly="true"/>-->
- <!-- mybatis - 集成的第三方缓存ehcache-->
- <cache type="org.mybatis.caches.ehcache.EhcacheCache">
- <!-- 缓存创建以后,最后一次访问缓存,间隔多久缓存失效(单位s) -->
- <property name="timeToIdleSeconds" value="3600"/>
- <!-- 缓存创建日期起到失效时的时间间隔(单位s) -->
- <property name="timeToLiveSeconds" value="3600"/>
- <!-- 堆内存中缓存对象数(0:没有限制) -->
- <property name="maxEntriesLocalHeap" value="1000"/>
- <!-- 磁盘中的对象数,默认为0不限制 -->
- <property name="maxEntriesLocalDisk" value="1000000"/>
- <!-- 内存存储与释放策略(FIFO:先进先出,LFU:一直以来最少被使用的,LRU:最近最少使用的) -->
- <property name="memoryStoreEvictionPolicy" value="LRU"/>
- </cache>
- <select id="getDepartmentInfo" parameterType="integer" resultType="department">
- select * from department where dept_id = #{deptId}
- </select>
- <!-- getDepartmentInfoWithEmploye方法中的 map1 对应我们<resultMap>标签中的 id属性 type 映射结果的全类名
- column:对应我们数据库中的字段 property:对应我们java对象中的属性名
- <id>:映射字段中的id属性
- <result>:映射字段中的非id属性
- collection:一对多映射标签
- ofType="employee" :一对多的属性名的类型的全类名
- -->
- <resultMap id="map1" type="com.sf.entity.Department">
- <id column="dept_id" property="deptId"></id>
- <result column="dept_name" property="deptName"></result>
- <collection property="employees" ofType="employee">
- <id column="emp_id" property="empId"></id>
- <result column="emp_name" property="empName"></result>
- <result column="salary" property="salary"></result>
- </collection>
- </resultMap>
- <select id="getDepartmentInfoWithEmployee" parameterType="integer" resultMap="map1">
- select * from department t1 , employee t2 where t1.dept_id = t2.dept_id and t1.dept_id = #{deptId}
- </select>
- <!--
- <collection>标签中的 column="dept_id" : 我们关联表的外键
- select : 是查询员工信息的接口
- -->
- <resultMap id="deptMap2" type="department">
- <id column="dept_id" property="deptId"></id>
- <result column="dept_name" property="deptName"></result>
- <collection property="employees" ofType="employee" column="dept_id" select="com.sf.mapper.DepartmentMapper.getEmployeeInfoByDeptId">
- <id column="emp_id" property="empId"></id>
- <result column="emp_name" property="empName"></result>
- <result column="salary" property="salary"></result>
- </collection>
- </resultMap>
- <!-- 分为俩步骤:
- 1.根据dept_id查询部门信息
- 2.根据的dept_id查询员工的信息
- -->
- <select id="getDepartmentInfoWithEmployee2" parameterType="integer" resultMap="deptMap2">
- select * from department where dept_id = #{deptId}
- </select>
- <select id="getEmployeeInfoByDeptId" parameterType="integer" resultType="employee">
- select * from employee where dept_id = #{deptId}
- </select>
- </mapper>
|