例子店铺表和店铺图片表是一对多的关系

店铺对应实体:

public class StoreVo implements Serializable {
    private static final long serialVersionUID = 1L;

    //
    private Long id;
    //会员id
    private Long userId;
    //主体类型 1.个人 2.个体工商户
    private Integer registrationType;
    //店铺名称
    private String storeName;
    //店铺地址
    private String storeAddress;
    //工商注册号
    private String registrationNo;
    //营业执照
    private String registrationImgUrl;
    //主营产品
    private String storeProduct;
    //负责人
    private String principalName;
    //联系电话
    private String telNumber;
    //认证状态:1.已认证 0未认证 2已驳回
    private Integer authStatus;
    //创建时间
    private Date createDate;

    //店铺图片列表
    private List<StoreImgVo> storeImgVos;
}

 

 店铺图片实体:

public class StoreImgVo implements Serializable {
    private static final long serialVersionUID = 1L;

    //
    private Long id;
    //店铺Id
    private Long storeId;
    //店铺图片
    private String storeImgUrl;
}

 

 店铺

<resultMap type=\"com.snserver.entity.StoreVo\" id=\"storeMap\">
        <result property=\"id\" column=\"id\"/>
        <result property=\"userId\" column=\"user_id\"/>
        <result property=\"registrationType\" column=\"registration_type\"/>
        <result property=\"storeName\" column=\"store_name\"/>
        <result property=\"storeAddress\" column=\"store_address\"/>
        <result property=\"registrationNo\" column=\"registration_no\"/>
        <result property=\"registrationImgUrl\" column=\"registration_img_url\"/>
        <result property=\"storeProduct\" column=\"store_product\"/>
        <result property=\"principalName\" column=\"principal_name\"/>
        <result property=\"telNumber\" column=\"tel_number\"/>
        <result property=\"authStatus\" column=\"auth_status\"/>
        <result property=\"createDate\" column=\"create_date\"/>
    </resultMap>
    <resultMap type=\"com.snserver.entity.StoreVo\" id=\"stortImgMap\"
               extends=\"storeMap\">
        <collection property=\"storeImgVos\" ofType=\"com.snserver.entity.StoreImgVo\">
            <id property=\"id\" column=\"sid\" />
            <result property=\"storeId\" column=\"storeId\" />
            <result  property=\"storeImgUrl\" column=\"storeImgUrl\"/>
        </collection>
    </resultMap>
     <select id=\"queryUserId\" resultMap=\"stortImgMap\">
		select
			a.`id`,
			a.`user_id`,
			a.`registration_type`,
			a.`store_name`,
			a.`store_address`,
			a.`registration_no`,
			a.`registration_img_url`,
			a.`store_product`,
			a.`principal_name`,
			a.`tel_number`,
			a.`auth_status`,
			a.`create_date`,
			b.`id` as sid,
			b.`store_id` as storeId,
			b.`store_img_url` as storeImgUrl
		from tbl_store as a left join tbl_store_img as b on a.id = b.store_id
		where user_id = #{userId}
	</select>
</mapper>

 

收藏 打印