07-MyBatis_sql标签和include标签的使用




1. 源码下载:



    参看06-MyBatis_关联映射之多对一的下载


2. 功能:

    

    封装SQL语句, 调用

   如:


             id, name, address


3. 使用:

/* 

    SELECT o.*, p.*
    FROM orders o 
      JOIN person p ON (p.personId=o.pid)
    WHERE o.orderId = 'O_00001'     



*/  @Test public void testSelectOrderById2() throws Exception {
        SqlSession session = sqlSessionFactory.openSession();
        
        Order order = session.selectOne("com.hehe.mybatis.domain.Order.selectOrderById2", "O_00001");
        System.out.println(
                        order.getId() + "\t" +
                        order.getNumber() + "\t" +
                        order.getPrice() + "\t" +
                        order.getPerson().getId() + "\t" +
                        order.getPerson().getName() + "\t" +
                        order.getPerson().getAddress() + "\t" +
                        order.getPerson().getTel()
                );      
        session.close();
    }




你可能感兴趣的:(MyBatis,MyBatis-学习笔记)