package com.cesgroup.Interceptor;

import com.cesgroup.pojo.Student;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;

import java.io.InputStream;

public class MybatisLogInterceptorTest {

    private SqlSession sqlSession=null;
    private SqlSessionFactory sqlSessionFactory;

    @Before
    public void configMybatis() {
        String resource = "mybatis-config.xml";
        InputStream inputStream;
        try {
            inputStream = Resources.getResourceAsStream(resource);
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            sqlSession= sqlSessionFactory.openSession(false);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if(sqlSession!=null) {
                sqlSession.close();
            }
        }
    }
    @Test
    public void testMybatisSelectStudent() {
        Student stu = sqlSession.selectOne("StudentMapper.selectStudetInfo", 16);
        System.out.println(stu);
        sqlSession.close();
    }
}