Mybatis相应API
作者:互联网
Mybatis相应API
1、SqlSession工厂构造器SqlSessionFactoryBuilder
2、SqlSession工厂对象sqlSessionFactory
3、SqlSession会话对象
<!--查询一个数据-->
<select id="findBy" resultType="user" parameterType="int">
select * from user where id=#{id}
</select>
@Test
public void test05() throws IOException {
//获得核心配置文件
InputStream resourceAsStream = Resources.getResourceAsStream("sqlMapConfig.xml");
//获得session工厂对象
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
//获得session回话对象
SqlSession sqlSession = sqlSessionFactory.openSession();
//执行操作 参数:namespace+id
User user = sqlSession.selectOne("userMapper.findBy", 1);
//打印数据
System.out.println(user);
//释放资源
sqlSession.close();
}
标签:sqlSessionFactory,sqlSession,SqlSession,API,user,Mybatis,id,相应 来源: https://blog.csdn.net/qq_56299755/article/details/122827888