MyBatis工作原理

Mybatis工作原理:


我们的应用程序通过mybatis提供的api,增删改查方法来访问数据库,
api底层调用了jdbc ,只不过mybatis对jdbc的封装是不完全封装,
里面的sql语句需要我们自己来写,sql语句写在映射文件mapper.xml中的,
而映射文件是注册在主配置文件mybatis.xml中的,主配置文件是通过api加载进来的


,// 1.加载主配置文件
InputStream inputStream = Resources.getResourceAsStream("mybatis.xml");

// 2.创建sqlsessionfactory对象
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder()
.build(inputStream);

sqlSession = sqlSessionFactory.openSession();
// 4.进行增删该查方法
sqlSession.insert("insertStudent",student);

sqlSession.commit();

} catch (IOException e) {

e.printStackTrace();
}finally{

if(null != sqlSession){

sqlSession.close();
}
}

Xml中的作用:* >=0 + >=1 ? <=1

原文地址:https://www.cnblogs.com/xiaohouzai/p/6759620.html