您的位置:首页 > 其它

mybatis 配置-简单记录一下,免得忘记了

2016-10-27 15:26 351 查看
<!-- 用户信息 -->
<resultMap id="BaseResultMap" type="com.test.model.User" >
<id column="id" property="id" jdbcType="BIGINT" />
<result column="user_name" property="userName" jdbcType="VARCHAR" />
<result column="user_status" property="userStatus" jdbcType="SMALLINT" />
</resultMap>
<!-- 用户与用户的备注信息信息,一个用户有一个用户备注信息 select * from user u inner join remarkInfo r on u.id=r.user_id-->
<resultMap  id="userAndRemarkInfoResultMap" extends="BaseResultMap" type="com.test.model.User">
<association property="userRemarkInfo" resultMap="userRemarkInfoBaseResultMap"></association>
</resultMap>
<!-- 用户的备注信息信息 -->
<resultMap id="userRemarkInfoBaseResultMap" type="com.test.model.UserRemarkInfo" >
<id column="remarkId" property="id" jdbcType="BIGINT" /> <!-- remarkId 为别名 ,查询用户以及用户备注信息的时候防止id字段相同值覆盖 -->
<result column="use_age" property="useCpu" jdbcType="INTEGER" />
<result column="use_sex" property="useMemory" jdbcType="SMALLINT" />
<result column="user_id" 			jdbcType="BIGINT" 		property="userId" />
</resultMap>
<!-- 用户与用户的备注信息信息以及用户的房产信息,一个用户有一个用户备注信息,多个房产信息
select * from user u inner join remarkInfo r on u.id=r.user_id  left join hourseInfo h on u.id=h.user_id
-->
<resultMap  id="userAndRemarkInfoAndHourseInfoResultMap" extends="userAndRemarkInfoResultMap" type="com.test.model.User">
<collection property="hourseList" ofType="com.chinac.cpc.model.hourse" column="userId">
<id 	column="h_id" 				jdbcType="BIGINT" 		property="id" />
<result column="hourse_name" 		jdbcType="VARCHAR" 		property="hourseName" />
<result column="hourse_addr" 		jdbcType="VARCHAR" 		property="hourseAddr" />
<result column="user_id" 			jdbcType="BIGINT" 		property="userId" />
</collection>
</resultMap>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: