<!-- 用户信息 -->
<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>
mybatis 配置-简单记录一下,免得忘记了
最新推荐文章于 2023-10-06 22:48:16 发布