File tree Expand file tree Collapse file tree 4 files changed +24
-13
lines changed
spitter-persistence-mybatis/src/main
com/vonzhou/spitter/mappers Expand file tree Collapse file tree 4 files changed +24
-13
lines changed Original file line number Diff line number Diff line change 1
1
package com .vonzhou .spitter ;
2
2
3
3
import com .vonzhou .spitter .domain .Spitter ;
4
+ import com .vonzhou .spitter .service .SpitterService ;
4
5
import org .springframework .context .ApplicationContext ;
5
6
import org .springframework .context .support .ClassPathXmlApplicationContext ;
6
7
8
+ import java .util .List ;
9
+
7
10
/**
8
11
* Created by vonzhou on 16/4/5.
9
12
*/
10
13
public class Main {
14
+
15
+
11
16
public static void main (String [] args ) {
12
- ApplicationContext context = new ClassPathXmlApplicationContext ("dataSource-context .xml" );
17
+ ApplicationContext context = new ClassPathXmlApplicationContext ("applicationContext .xml" );
13
18
//JdbcSpitterDao dao = (JdbcSpitterDao)context.getBean("jdbcSpitterDao");
14
19
20
+ SpitterService spitterService = (SpitterService ) context .getBean ("spitterService" );
21
+
15
22
16
23
Spitter s = new Spitter ();
17
24
s .setFullName ("vonzhou" );
@@ -22,8 +29,7 @@ public static void main(String[] args) {
22
29
// dao.addSpitter(s);
23
30
24
31
//Spitter spitter = dao.getSpitterById(1);
25
- System .out .println (s .getUsername ());
26
-
27
-
32
+ List <Spitter > list = spitterService .findAllSpitters ();
33
+ System .out .println (list .size ());
28
34
}
29
35
}
Original file line number Diff line number Diff line change 3
3
import com .vonzhou .spitter .domain .Spitter ;
4
4
import com .vonzhou .spitter .mappers .SpitterMapper ;
5
5
import org .apache .ibatis .session .SqlSession ;
6
+ import org .mybatis .spring .SqlSessionTemplate ;
6
7
import org .springframework .beans .factory .annotation .Autowired ;
7
8
import org .springframework .stereotype .Service ;
8
9
import org .springframework .transaction .annotation .Transactional ;
12
13
/**
13
14
* Created by vonzhou on 16/7/12.
14
15
*/
15
- @ Service
16
+ @ Service ( value = "spitterService" )
16
17
@ Transactional
17
18
public class SpitterService {
18
19
19
20
@ Autowired
20
- private SqlSession sqlSession ;
21
-
22
- @ Autowired
23
- private SpitterMapper spitterMapper ;
21
+ private SqlSessionTemplate sqlSessionTemplate ;
24
22
25
23
public List <Spitter > findAllSpitters () {
26
- // SpitterMapper spitterMapper = sqlSession.getMapper(SpitterMapper.class);
27
- return spitterMapper .findAllSpitters ();
24
+ try {
25
+ SpitterMapper spitterMapper = sqlSessionTemplate .getMapper (SpitterMapper .class );
26
+ return spitterMapper .findAllSpitters ();
27
+ }catch (Exception e ){
28
+ System .out .println ("----------------------------" );
29
+ System .out .println (e .getCause ());
30
+ System .out .println ("+++++++++++++++++++++++++++++" );
31
+ }
32
+ return null ;
28
33
}
29
34
}
Original file line number Diff line number Diff line change 30
30
</bean >
31
31
32
32
33
- <bean id =" sqlSession " class =" org.mybatis.spring.SqlSessionTemplate" >
33
+ <bean id =" sqlSessionTemplate " class =" org.mybatis.spring.SqlSessionTemplate" >
34
34
<constructor-arg index =" 0" ref =" sqlSessionFactory" />
35
35
</bean >
36
36
Original file line number Diff line number Diff line change 15
15
</resultMap >
16
16
17
17
<select id =" findAllSpitters" resultMap =" SpitterResult" >
18
- select * from SPITTER
18
+ select * from SPITTER2
19
19
</select >
20
20
21
21
</mapper >
You can’t perform that action at this time.
0 commit comments