<mappernamespace="com.example.mybatis.mapper.OrderCustomerStepMapper"> <!-- 步骤1:独立查询客户(被分步调用的基础方法) --> <selectid="getCustomerById"resultType="com.example.mybatis.bean.Customer"> select * from t_customer where id = #{id} </select>
<!-- 步骤3:查询订单的入口方法(触发分步查询) --> <selectid="getOrderByIdAndCustomerStep"resultMap="OrderCustomerStepRM"> select * from t_order where id = #{id} </select> </mapper>
<!-- 步骤3:查询客户的入口方法(触发分步查询) --> <selectid="getCustomerByIdAndOrdersStep"resultMap="CustomerOrdersStepRM"> select * from t_customer where id = #{id} </select> </mapper>
<mappernamespace="com.example.mybatis.mapper.OrderCustomerStepMapper"> <!-- 基础方法:查询客户(被第一层分步调用) --> <selectid="getCustomerById"resultType="com.example.mybatis.bean.Customer"> select * from t_customer where id = #{id} </select>
<!-- 基础方法:查询客户的所有订单(被第二层分步调用) --> <selectid="getOrdersByCustomerId"resultType="com.example.mybatis.bean.Order"> select * from t_order where customer_id = #{cId} </select>
<!-- 超级分步查询入口:查询订单,同时加载客户及客户的所有订单 --> <selectid="getOrderWithCustomerAndOrdersSuperStep"resultMap="OrderCustomerWithOrdersSuperStepRM"> select * from t_order where id = #{id} </select> </mapper>