xml配置:
<typeAliases>
<typeAlias alias="fClass" type="com.model.FirstClass" />
<typeAlias alias="sClass" type="com.model.SingerClass" />
<typeAlias alias="video" type="com.model.MvVideo" />
</typeAliases>
<resultMap id="getMvSingerFClassResult" type="video">
<id property="id" column="Id" />
<result column="MvName" property="mvName" />
<result column="MvPhoto" property="mvPhoto" />
<result column="SingerId" property="singerId" />
<result column="MvSortId" property="mvSortId" />
<result column="Click" property="click" />
<result column="AddTime" property="addTime" />
<result column="PlayTime" property="playTime" />
<result column="IsGood" property="isGood" />
<result column="IsBad" property="isBad" />
<result column="IsLike" property="isLike" />
<result column="MvPath" property="mvPath" />
<result column="IsRec" property="isRec" />
<result column="IsHot" property="isHot" />
<result column="Intro" property="intro" />
<association property="firstClass" javaType="com.model.FirstClass">
<result property="id" column="Id" />
<result property="fclassname" column="FClassName" />
</association>
<association property="singer" javaType="com.model.SingerClass">
<result property="id" column="Id" />
<result property="sclassName" column="SClassName" />
</association>
</resultMap>
<select id="selectMvList" resultMap="getMvSingerFClassResult">
<![CDATA[
select * From mvVideo as v,singerclass as s ,firstclass as f where v.SingerId = s.Id and f.Id=s.FClassId
]]>
</select>
JAVA:
List<MvVideo> mvList = mvVideoService.selectMvList();
for (MvVideo mvVideo : mvList) {
System.out.println(mvVideo.getMvName());
System.out.println(mvVideo.getFirstClass().getFclassname());
System.out.println(mvVideo.getSinger().getSclassName());
}
request.setAttribute("mvList", mvList);
JSP:
<c:forEach var="data" items="${mvList}">
mvName:${data.mvName}<br/>
sclassName:${data.singer.sclassName}<br/>
mvSortName:${data.firstClass.fclassname}<br/>
</c:forEach>
详细介绍:http://legend2011.blog.51cto.com/3018495/926219