一、确定数据源
select m.id,m.a,m.b,d.main_id,d.aa,d.bb
from table_main as m
left join table_detail as d on m.id=d.main_id
where
m.status_id= 2
and m.x_id = #{x_id}
二、定义数据视图类


三、定义mapper接口

四、编写xml语句
<resultMap id="ResultMap" type="*MainVo">
<result property="*" column="*"/>
<collection property="productsList" column="id"
javaType="ArrayList" ofType="*SubVo">
<result property="productName" column="erp_product_short_name"/>
</collection>
</resultMap>
<select id="select*By*" parameterType="String" resultMap="ResultMap">
select m.id,m.a,m.b,d.main_id,d.aa,d.bb
from table_main as m
left join table_detail as d on m.id=d.main_id
where
m.status_id= 2
and m.x_id = #{x_id}
</select>
五、编写server(可添加其他逻辑)调用mapper
六、control层调用server方法
可参考:
https://blog.youkuaiyun.com/weixin_34259559/article/details/91848771
https://blog.youkuaiyun.com/qq_40588618/article/details/89517692
本文详细介绍了如何使用MyBatis进行左连接查询,并通过XML映射实现复杂数据结构的转换,包括主从表数据的整合,以及自定义结果集映射,为开发者提供了一个完整的案例。

被折叠的 条评论
为什么被折叠?



