2018-02-16-2.mybatis一对一映射情况解析

junit测试类代码:(调用接口)

private SqlSessionFactory ssf = null;
    @Before
    public void before() throws Exception {
        InputStream is = Resources.getResourceAsStream("SqlMapConfig.xml");
        this.ssf = new SqlSessionFactoryBuilder().build(is);
    }

    @Test
    public void aaa() {
        SqlSession sqlSession = this.ssf.openSession();

        OrderMapper mapper = sqlSession.getMapper(OrderMapper.class);

        List orders = mapper.selectAllOrdersWithUser();

        for (Orders order :
                orders) {
            System.out.println(order);
        }
    }

接口mapper类代码:

/**
 * Created by syk on 2018/2/16.
 */
public interface OrderMapper {

    public List selectAllOrders();


    //多对一

    public List selectAllOrdersWithUser();
}

接口对应的xml文件代码:









    
        
    

    

    
        
        
        
        
        
        
            
            
        
    
    

需要注意的是:在一对一情况,对象中嵌套了另外一个对象,那么resultMap映射关系中正常可以忽略的属性都不能够忽略,否则无法成功映射

你可能感兴趣的:(2018-02-16-2.mybatis一对一映射情况解析)