<resultMap id="ActivityMap" type="ActivityDetailDTO" > <id column="id" property="id"/> <result property="name" column="name" /> <result property="exchangeType" column="exchange_type"/> <result property="activityStatus" column="activity_status" /> <collection property="shopList" javaType="List" ofType="ShopDTO" column="id" select="selectShopList"> <result property="shopId" column="shop_id" /> <result property="shopName" column="shop_name" /> <result property="activityId" column="activityId" /> </collection> </resultMap> <select id="getActivityDetail" parameterType="long" resultMap="ActivityMap"> select id, name,exchange_type,activity_status from activity where id=#{id} </select> 上面查询id不能漏 <select id="selectShopList" parameterType="long" resultType="ShopDTO"> select shop_id ,shop_name as shopName,activity_id as activityId from shop where activity_id =#{id} </select>
mybatis一对多嵌套查询
最新推荐文章于 2024-07-13 15:29:04 发布