<?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.zheng.cms.dao.mapper.UserVOMapper">

	<!-- 结果映射关系 -->
	<resultMap id="UserResultMap" type="com.zheng.cms.dao.model.UserVO">
		<id column="u_id" property="id"/>
		<result column="username" property="username"/>
		<result column="password" property="password"/>
		<result column="nickname" property="nickname"/>
		<result column="sex" property="sex"/>
		<result column="ctime" property="ctime"/>
		<result column="content" property="content" />
		<collection column="userid" property="books" ofType="com.zheng.cms.dao.model.CmsBook">
			<id column="b_id" property="id"/>
			<result column="userid" property="userid"/>
			<result column="name" property="name"/>
		</collection>
	</resultMap>
	
	<!-- 查询一对多的所有记录 -->
	<select id="selectUserWithBook" resultMap="UserResultMap" parameterType="int">
		select
			u.id u_id,u.username,u.password,u.nickname,u.sex,u.ctime,u.content,
			b.id b_id,b.userid,b.name
		from
			cms_user u
		left join
			cms_book b
		on
			u.id=b.userid
		where
			u.id=#{id,jdbcType=INTEGER}
	</select>

	<!-- 缓存 -->
	<cache type="org.mybatis.caches.ehcache.LoggingEhcache" />
	
</mapper>