Mybaits利用resultMap实现一对多

对于一对多的resultMap的定义

    
    
    
    
    
    
    
    
    
    
        
        
        
        
        
    




    
    
    
    
     
         
         
         
         
         
     
    



调用resultMap


mapper中的接口
public List findOrderAndOrderDetailResultMap() throws Exception;


Test
public class OrdersMapperCustomTest {
    private SqlSessionFactory sqlSessionFactory;
    @Before
    public void setUp() throws Exception {
        InputStream inputStream = Resources.getResourceAsStream("SqlMapConfig.xml");
        sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
    }
    
    @Test
    public void testFindOrderAndOrderDetailResultMap() throws Exception {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        OrdersMapperCustom ordersMapperCustom = sqlSession.getMapper(OrdersMapperCustom.class);
        
        List orderList = ordersMapperCustom.findOrderAndOrderDetailResultMap();
        
        System.out.println(orderList);
    }

}


你可能感兴趣的:(java-MyBetis)