标签:str select nbsp ati row 框架 string try 方法
1、先初始化SqlSessionFactory对象:
MyBatis(8)——运行原理-初始化SqlSessionFactory
2、使用sqlSessionFactory对象获取SqlSession对象:
MyBatis(9)——运行原理-获取SqlSession对象
3、使用SqlSession的getMapper方法获取接口的代理对象:
MyBatis(10)——运行原理-getMapper获取接口的代理对象
4、最后调用mapper的查询方法:
MyBatis(11)——运行原理-查询流程原理
@Test
public void testInterface() throws IOException {
String resource = "mybatis-config.xml";
InputStream inputStream = Resources.getResourceAsStream(resource);
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
SqlSession session = sqlSessionFactory.openSession();
try {
EmployeeMapper mapper = session.getMapper(EmployeeMapper.class);
Employee employee = mapper.selectEmployee(121);
System.out.println(employee);
} finally {
session.close();
}
}
标签:str select nbsp ati row 框架 string try 方法
原文地址:https://www.cnblogs.com/starfall/p/10325264.html