实体对象里定义的集合图片
private List<CompanyImagesModel> [color=darkred]companyImages[/color];
一、
1、定义 resultMap :
<!-- 图片 -->
<resultMap id="[color=orange]BaseResultMap_images[/color]" type="com.healthengine.model.CompanyModel" extends="BaseResultMap" >
<!-- 添加一对多的关联对象 -->
<collection property="[color=darkred]companyImages[/color]" column="companyImagesId" ofType="com.healthengine.model.CompanyImagesModel">
<id column="question_images_id" property="companyImagesId" jdbcType="BIGINT" />
<result column="company_id" property="companyId" jdbcType="BIGINT" />
<result column="type" property="type" jdbcType="INTEGER" />
<result column="image_path" property="imagePath" jdbcType="VARCHAR" />
</collection>
</resultMap>
2.sql查询
<!-- 查看公司信息关联图片 -->
<select id="selectModelAndImagesByPrimaryKey" resultMap="[color=orange]BaseResultMap_images[/color]" parameterType="java.lang.Long" >
select
<include refid="Base_Column_List_images" />,[color=red]img.company_images_id, img.company_id, img.image_path, img.type,[/color]
SUBSTRING(city.merger_name,4) as city_name,city.parent_id as city_parentId
from tb_company c
[color=red] left join tb_company_images img on c.company_id = img.company_id and img.flag=1[/color]
LEFT JOIN tb_city city on c.city_id = city.city_id
where c.flag=1 and c.company_id = #{companyId,jdbcType=BIGINT}
</select>
二、
<!-- 关联图片表 -->
private List<CompanyImagesModel> picture;
1、定义 resultMap :
<resultMap id="[color=red]BaseResultMap_leftJoin_images[/color]" type="com.healthengine.model.CompanyModel" extends="BaseResultMap" >
<collection property="picture" column="{[color=green]companyId[/color]=company_id,[color=olive]picture_view_path_pre[/color]=picture_view_path_pre}" select="com.healthengine.mapper.CompanyImagesModelMapper.[color=yellow]selectByInformationId[/color]" >
</collection>
</resultMap>
2.sql查询:
<!-- 根据会员Id查看公司详情 -->
<select id="selectByMemberId" resultMap="[color=red]BaseResultMap_leftJoin_images[/color]" parameterType="java.util.Map" >
select
<include refid="Base_Column_List_images" />, city.name as city_name,
#{picture_view_path_pre} as picture_view_path_pre
FROM tb_company c
LEFT JOIN tb_city city on c.city_id = city.city_id
where c.flag=1 and c.member_id = #{memberId,jdbcType=BIGINT}
</select>
3.圖片表sql
<select id="[color=yellow]selectByInformationId[/color]" resultMap="BaseResultMap" parameterType="java.util.Map" >
select
<include refid="Base_Column_List_images" />, CONCAT(#{[color=olive]picture_view_path_pre[/color]},img.image_path) as imagePath,
img.image_path as localHead_Path
from tb_company_images img
where img.flag=1 and img.company_id = #{[color=green]companyId[/color],jdbcType=BIGINT}
</select>
[color=olive]companyId[/color] 和 [color=olive]picture_view_path_pre[/color]需要的参数需要从第一个Mapper.xml里传过来。
private List<CompanyImagesModel> [color=darkred]companyImages[/color];
一、
1、定义 resultMap :
<!-- 图片 -->
<resultMap id="[color=orange]BaseResultMap_images[/color]" type="com.healthengine.model.CompanyModel" extends="BaseResultMap" >
<!-- 添加一对多的关联对象 -->
<collection property="[color=darkred]companyImages[/color]" column="companyImagesId" ofType="com.healthengine.model.CompanyImagesModel">
<id column="question_images_id" property="companyImagesId" jdbcType="BIGINT" />
<result column="company_id" property="companyId" jdbcType="BIGINT" />
<result column="type" property="type" jdbcType="INTEGER" />
<result column="image_path" property="imagePath" jdbcType="VARCHAR" />
</collection>
</resultMap>
2.sql查询
<!-- 查看公司信息关联图片 -->
<select id="selectModelAndImagesByPrimaryKey" resultMap="[color=orange]BaseResultMap_images[/color]" parameterType="java.lang.Long" >
select
<include refid="Base_Column_List_images" />,[color=red]img.company_images_id, img.company_id, img.image_path, img.type,[/color]
SUBSTRING(city.merger_name,4) as city_name,city.parent_id as city_parentId
from tb_company c
[color=red] left join tb_company_images img on c.company_id = img.company_id and img.flag=1[/color]
LEFT JOIN tb_city city on c.city_id = city.city_id
where c.flag=1 and c.company_id = #{companyId,jdbcType=BIGINT}
</select>
二、
<!-- 关联图片表 -->
private List<CompanyImagesModel> picture;
1、定义 resultMap :
<resultMap id="[color=red]BaseResultMap_leftJoin_images[/color]" type="com.healthengine.model.CompanyModel" extends="BaseResultMap" >
<collection property="picture" column="{[color=green]companyId[/color]=company_id,[color=olive]picture_view_path_pre[/color]=picture_view_path_pre}" select="com.healthengine.mapper.CompanyImagesModelMapper.[color=yellow]selectByInformationId[/color]" >
</collection>
</resultMap>
2.sql查询:
<!-- 根据会员Id查看公司详情 -->
<select id="selectByMemberId" resultMap="[color=red]BaseResultMap_leftJoin_images[/color]" parameterType="java.util.Map" >
select
<include refid="Base_Column_List_images" />, city.name as city_name,
#{picture_view_path_pre} as picture_view_path_pre
FROM tb_company c
LEFT JOIN tb_city city on c.city_id = city.city_id
where c.flag=1 and c.member_id = #{memberId,jdbcType=BIGINT}
</select>
3.圖片表sql
<select id="[color=yellow]selectByInformationId[/color]" resultMap="BaseResultMap" parameterType="java.util.Map" >
select
<include refid="Base_Column_List_images" />, CONCAT(#{[color=olive]picture_view_path_pre[/color]},img.image_path) as imagePath,
img.image_path as localHead_Path
from tb_company_images img
where img.flag=1 and img.company_id = #{[color=green]companyId[/color],jdbcType=BIGINT}
</select>
[color=olive]companyId[/color] 和 [color=olive]picture_view_path_pre[/color]需要的参数需要从第一个Mapper.xml里传过来。