u类定义
一方:
publicclass UserObj {
privateint id;
privateString name;
private int age;
private List<ResultObj> resultList = newArrayList();
}
u多方:
publicclass ResultObj {
privateint id;
privateint point;
private UserObj user;
}
<!-- 定义类别名 -->
<typeAlias alias="users"type="com.map.UserObj"/>
<typeAlias alias="results"type="com.map.ResultObj"/>
<!-- 定义按用户ID查询用户。里面包括成绩集合 -->
<select id="findById" resultMap="user_Result">
select * from t_user where t_id=#{id}
</select>
定义用户结果集
u <!-- 定义按用户ID查询成绩,参数来自用户对象的ID -->
<select id="resultByUid" resultMap="resultData">
select* from t_result where uid=#{uid}
</select>
u<!-- 定义按成绩ID查询成绩 -->
<selectid="findResultById" resultMap="rm" parameterClass="int">
select * from t_result where id=#{id};
</select>
<!--column为外键列名,select表示引用另一个select标签查询结果填充该属性值- ->
u<!-- 定义按用户ID查询用户 -->
<select id="findUserById" resultType="user" >
select * from t_user where id=#{id};
</select>