代码
public class OrdersMapperTest {
private SqlSessionFactory sqlSessionFactory = null;
/**
* 提取sqlSessionFactory对象
* @throws IOException
*/
@Before
public void init() throws IOException{
// 1.加载配置文件
InputStream inputStream = Resources.getResourceAsStream("sqlMapConfig.xml");
// 2.读取配置文件的内容
SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
sqlSessionFactory = builder.build(inputStream);
}
/**
* 测试查询全部订单数据
*/
@Test
public void queryAllOrdersTest(){
// 1.创建sqlSession对象
SqlSession sqlSession = this.sqlSessionFactory.openSession();
// 2.使用sqlSession对象,获取mapper代理对象
OrdersMapper mapper = sqlSession.getMapper(OrdersMapper.class);
// 3.使用mapper对象,调用方法执行
List<Orders> list = mapper.queryAllOrders();
for(Orders o:list){
System.out.println(o);
}
// 4.释放资源
sqlSession.close();
}