association多表查询

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值