mybatis中关联查询(一对一)的使用总结(3)

在使用mybatis时,经常会用到关联查询,下面来总结一下关联查询(一对一)的使用(3)

一、首先说一下一对一的关联查询,一对一关联查询建议使用标签来完成

1.第三种使用标签的方法,直截了当,看代码:

1.1 新建实体类

public class CustDetailFME {
	
	private CustDetail custDetail;
	private CustFamily custFamily;
	
	public CustDetail getCustDetail() {
		return custDetail;
	}
	public void setCustDetail(CustDetail custDetail) {
		this.custDetail = custDetail;
	}
	public CustFamily getCustFamily() {
		return custFamily;
	}
	public void setCustFamily(CustFamily custFamily) {
		this.custFamily = custFamily;
	}
}

1.2 主表对应的sql映射接口

CustDetailFME custDetailFMESelectByCustId(@Param("custId") String custId);

1.3 主表的sql文件

<resultMap type="com.hbcfc.yusys.cmis.customer.mapper.domain.CustDetailFME" id="CustDetailFMEMap" >
        <association property="custDetail" javaType="com.hbcfc.yusys.cmis.customer.mapper.domain.CustDetail" >
			<id property="custId" column="cust_id"/>
			<result property="indivMobile" column="indiv_mobile"/>
			<result property="regMobile" column="reg_mobile"/>
			<result property="localResid" column="local_resid"/>
		</association>
		<association property="custDetail" javaType="com.hbcfc.yusys.cmis.customer.mapper.domain.CustFamily" columnPrefix="cd_">
			<id property="custId" column="cust_id"/>
			<result property="custNat" column="cust_nat"/>
			<result property="familyId" column="family_id"/>
		</association>
	</resultMap>
<select id="custDetailFMESelectByCustId" resultMap="CustDetailFMEMap">
		select a.cust_id,a.indiv_mobile,a.reg_mobile,a.localResid,b.cust_id cd_cust_id,b.cust_nat cd_cust_nat,b.family_id cd_family_id from cmis_uat1.CUST_DETAIL a , cmis_uat1.CUST_FAMILY b
		where a.cust_id = b.cust_id and cust_id=#{custId}  
	</select>

(具体使用方法说明:
返回实体类中对象是一对一的;与第二种方法的区别在于返回的对象中可以是两个实体

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值