-
\톰캣은 SqlSessionFactory 를 준비 시켜 놓는다.
-
요청이 들어오면 SqlSessionFactory는 DB와의 connection 을 유지시키고 있는 SqlSession을 만든다.
-
connection은 되어 있으나, 어떤 sql을 날릴지는 아직 정해지지 않았다.
따라서 sqlsession은 mapper Interface를 만든다. //
mapperInterface aa= Sqlsession.getMapper( mapperImpl.clsss )
-
interface 에 지정되어 있는 메소드를 실행하게 되면 ,
그와 연결된 mapper 에 있는 sql 이 실행되게 된다
Post post = aa.methodA(); //리턴값이 같아야함
SqlSession session = sqlSessionFactory.openSession();
try {
BlogMapper mapper = session.getMapper(BlogMapper.class);
Blog blog = mapper.selectBlog(101);
}
finally {
session.close();
}
https://araikuma.tistory.com/481
[MyBatis] Mapper
지금까지 우리는 SqlSession에 직접 Statement ID 및 매개 변수를 전달하는 방법으로 SQL을 실행을 하였다. MyBatis는 이와는 별도로 Mapper라는 구조도 준비되어있다. Mapper를 사용하면 SqlSession을 직접 사용..
araikuma.tistory.com