2
我在MyBatis中遇到了一對多關係問題。我在我的數據庫中有一個可以有很多地址的用戶。用戶和地址表使用ID鏈接。但MyBatis只填充第一個地址。奇怪的是,當我單獨運行mySQL代碼時,它工作正常,所以我猜測它與我的MyBatis映射有關。MyBatis ResultMap Collection - 僅返回一行
<select id="fetchUserAddressList" parameterType="string" resultMap="userAddressResultMap">
SELECT user.user_name, address.id, address.address_value
FROM user
LEFT OUTER JOIN address
ON user.id = address.id
WHERE user.id = #{userId}
</select>
<resultMap id="userAddressResultMap" type="com.bean.User" >
<id property="userName" column="user_name" />
<collection property="addressList" column="id" notNullColumn="id"
ofType="com.bean.Address"
resultMap="addressResultMap" />
</resultMap>
<resultMap id="addressResultMap" type="com.bean.AddressBean" >
<id property="userId" column="id" />
<result property="userAddress" column="address_value" />
</resultMap>
任何人有任何想法?