mybatis 测试类编写

@Test

public void findById() throws IOException {

// 1.加载SqLMapConfig配置文件

InputStream resourceAsStream = Resources . getResourceAsStream(“SqlMapConfig . xcm1”);

//2.创建sqlSessionFactory工厂

SqlSessionFactory factory = new Sq1SessionFactoryBuilder() . build(resourceAsStream);

//3. sqlSessionFactory创建sqlSession

SqlSession sqlSession = factory.openSession();

//4.通过Session创建UserDao接口代理对象

UserDao mapper = sqlSession. getMapper(UserDao.class);

// 5.执行

User user = mapper .findById(1);

//6.输出执行结果

System. out . println(user .toString());

//7.关闭资湖

sqlSession. close();

resourceAsstream. close();

上一篇:操作文件的系统调用


下一篇:微信公众号、普通网页关闭当前页面