ecology_maven/test/mybatisTest/MybatisTest.java

45 lines
1.4 KiB
Java
Raw Normal View History

2021-12-16 12:59:01 +08:00
package mybatisTest;
import aiyh.utils.MybatisUtil;
import baseTest.BaseTest;
import mybatisTest.entity.License;
2021-12-16 15:15:34 +08:00
import mybatisTest.mapper.ITestMapper;
2021-12-16 12:59:01 +08:00
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();
2021-12-16 15:15:34 +08:00
ITestMapper mapper = session.getMapper(ITestMapper.class);
2021-12-16 12:59:01 +08:00
// Map<String, String> map = mapper.selectOne();
// System.err.println(map);
session.close();
}
@Test
public void test(){
SqlSessionManager sessionManager = MybatisUtil.getSessionManager("test-mybatis-config.xml");
2021-12-16 15:15:34 +08:00
ITestMapper mapper = sessionManager.getMapper(ITestMapper.class);
2021-12-16 12:59:01 +08:00
License license = mapper.selectOne();
System.out.println(license);
}
}