File tree Expand file tree Collapse file tree
main/java/com/javalearning/dao
test/java/com/javalearning/service Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .javalearning .dao ;
2+
3+ import com .javalearning .model .Book ;
4+ import com .javalearning .util .SessionFactoryUtil ;
5+ import org .apache .ibatis .session .SqlSession ;
6+ import org .apache .ibatis .session .SqlSessionFactory ;
7+
8+ /**
9+ * Created by renqun.yuan on 2015/12/12.
10+ */
11+ public class BookDaoOldWay {
12+
13+ private SqlSessionFactory sqlSessionFactory = SessionFactoryUtil .getSqlSessionFactory ().get ();
14+
15+ public Book queryBookById (Integer id ) {
16+ try (SqlSession sqlSession = sqlSessionFactory .openSession ()) {
17+ Book book = sqlSession .selectOne ("com.javalearning.dao.BookDao.selectBookById" , id );
18+ return book ;
19+ }
20+ }
21+ }
Original file line number Diff line number Diff line change 11package com .javalearning .service ;
22
33import com .google .common .collect .Lists ;
4+ import com .javalearning .dao .BookDaoOldWay ;
45import com .javalearning .model .Book ;
56import org .junit .Assert ;
67import org .junit .Test ;
@@ -99,4 +100,11 @@ public void testInsertBookWithoutConfigFile() {
99100 book .setAuthor ("果果" );
100101 bookService .insertBookWithoutConfigFile (book );
101102 }
103+
104+ @ Test
105+ public void testOldWayDao () {
106+ BookDaoOldWay bookDaoOldWay = new BookDaoOldWay ();
107+ Book book = bookDaoOldWay .queryBookById (6 );
108+ System .out .println (book );
109+ }
102110}
You can’t perform that action at this time.
0 commit comments