Mybatis master-slave table association query package returns results

First, determine the data source

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}

2. Define the data view class
Insert picture description here
Insert picture description here
3. Define the mapper interface
Insert picture description here
4. Write the xml statement

	<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>

Five, write server (additional logic can be added) call mapper Insert picture description here
Six, control layer call server method

Reference:
https://blog.csdn.net/weixin_34259559/article/details/91848771
https://blog.csdn.net/qq_40588618/article/details/89517692

Published 65 original articles · Like 16 · Visits 10,000+

Guess you like

Origin blog.csdn.net/s_156/article/details/105414458