本文主要是介绍mybatis中association的使用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
association通常用来映射一对一的关系
示例:
<resultMap type="com.ddwl.api.entity.xxx" id="resultItem"><result column="TrackingNumber" property="TrackingNumber"/><association property="shipperDetails" javaType="com.ddwl.api.entity.ShipperDetails"><result column="ShipperCode" property="ShipperCode"/><result column="ShipperName" property="ShipperName"/><result column="ShipperCompany" property="ShipperCompany"/><result column="ShipperPhoneNo" property="ShipperPhoneNo"/><result column="ShipperTelNo" property="ShipperTelNo"/><association property="shipperAddressDetails" javaType="com.ddwl.api.entity.ShipperAddressDetails"><result column="ShipperFullAddress" property="ShipperFullAddress"/><association property="shipperNormalisedAddress" javaType="com.ddwl.api.entity.ShipperNormalisedAddress"><result column="ShipperTownshipName" property="ShipperTownshipName"/><result column="ShipperCountyName" property="ShipperCountyName"/><result column="ShipperCityName" property="ShipperCityName"/><result column="ShipperProvinceName" property="ShipperProvinceName"/><result column="ShipperCountryCode" property="ShipperCountryCode"/><result column="ShipperCountryName" property="ShipperCountryName"/><result column="ShippingDriverCode" property="ShippingDriverCode"/><result column="ShippingDriverName" property="ShippingDriverName"/><result column="IsSendMessage" property="IsSendMessage"/><result column="ShippingArea" property="ShippingArea"/></association></association></association></resultMap>
注意:必须把 <association>放在 <result>后面
否则会出现如图异常:
这篇关于mybatis中association的使用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!