mybatis 主从表关联查询封装返回结果

一、确定数据源

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.csdn.net/weixin_34259559/article/details/91848771
https://blog.csdn.net/qq_40588618/article/details/89517692

发布了65 篇原创文章 · 获赞 16 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/s_156/article/details/105414458
今日推荐