Mybaits利用resultMap实现一对一

定义resultMap:

    
    
    
    
    
    
        
    
    
        
        
        
        
        
    


引用resultMap:



mapper:
public List findOrderUserResultMap() 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 testFindOrderUserResultMap() throws Exception {
		SqlSession sqlSession = sqlSessionFactory.openSession();
		OrdersMapperCustom ordersMapperCustom = sqlSession.getMapper(OrdersMapperCustom.class);
		
		List orderList = ordersMapperCustom.findOrderUserResultMap();
		
		System.out.println(orderList);
	}

}



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