package mybatisTest; import aiyh.utils.MybatisUtil; import baseTest.BaseTest; import mybatisTest.dao.ITestDAO; import mybatisTest.entity.License; 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.apache.ibatis.session.SqlSessionManager; import org.junit.Test; import java.io.Reader; /** * @author EBU7-dev1-ayh * create 2021/12/14 0014 12:52 */ public class MybatisTest extends BaseTest { //查询 @Test public void testName() throws Exception{ SqlSession session = null; Reader resourceAsReader = Resources.getResourceAsReader("WEB-INF/test-mybatis-config.xml"); SqlSessionFactory build = new SqlSessionFactoryBuilder().build(resourceAsReader); session = build.openSession(); ITestDAO mapper = session.getMapper(ITestDAO.class); // Map map = mapper.selectOne(); // System.err.println(map); session.close(); } @Test public void test(){ SqlSessionManager sessionManager = MybatisUtil.getSessionManager("test-mybatis-config.xml"); ITestDAO mapper = sessionManager.getMapper(ITestDAO.class); License license = mapper.selectOne(); System.out.println(license); } }