File tree Expand file tree Collapse file tree 4 files changed +25
-6
lines changed
src/test/java/org/apache/ibatis/submitted/basetest Expand file tree Collapse file tree 4 files changed +25
-6
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2009-2012 The MyBatis Team
2
+ * Copyright 2009-2013 The MyBatis Team
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -33,7 +33,7 @@ public class BaseTest {
33
33
34
34
@ BeforeClass
35
35
public static void setUp () throws Exception {
36
- // create a SqlSessionFactory
36
+ // create an SqlSessionFactory
37
37
Reader reader = Resources .getResourceAsReader ("org/apache/ibatis/submitted/basetest/mybatis-config.xml" );
38
38
sqlSessionFactory = new SqlSessionFactoryBuilder ().build (reader );
39
39
reader .close ();
@@ -61,4 +61,18 @@ public void shouldGetAUser() {
61
61
}
62
62
}
63
63
64
+ @ Test
65
+ public void shouldInsertAUser () {
66
+ SqlSession sqlSession = sqlSessionFactory .openSession ();
67
+ try {
68
+ Mapper mapper = sqlSession .getMapper (Mapper .class );
69
+ User user = new User ();
70
+ user .setId (2 );
71
+ user .setName ("User2" );
72
+ mapper .insertUser (user );
73
+ } finally {
74
+ sqlSession .close ();
75
+ }
76
+ }
77
+
64
78
}
Original file line number Diff line number Diff line change 18
18
public interface Mapper {
19
19
20
20
User getUser (Integer id );
21
+ void insertUser (User user );
21
22
22
23
}
Original file line number Diff line number Diff line change 1
1
<?xml version =" 1.0" encoding =" UTF-8" ?>
2
2
<!--
3
- Copyright 2009-2012 The MyBatis Team
3
+ Copyright 2009-2013 The MyBatis Team
4
4
5
5
Licensed under the Apache License, Version 2.0 (the "License");
6
6
you may not use this file except in compliance with the License.
21
21
<mapper namespace =" org.apache.ibatis.submitted.basetest.Mapper" >
22
22
23
23
<select id =" getUser" resultType =" org.apache.ibatis.submitted.basetest.User" >
24
- select * from users
24
+ select * from users where id = #{id}
25
25
</select >
26
26
27
+ <insert id =" insertUser" >
28
+ insert into users values(#{id}, #{name})
29
+ </insert >
30
+
27
31
</mapper >
Original file line number Diff line number Diff line change 1
1
<?xml version =" 1.0" encoding =" UTF-8" ?>
2
2
<!--
3
- Copyright 2009-2012 The MyBatis Team
3
+ Copyright 2009-2013 The MyBatis Team
4
4
5
5
Licensed under the Apache License, Version 2.0 (the "License");
6
6
you may not use this file except in compliance with the License.
34
34
</environments >
35
35
36
36
<mappers >
37
- <mapper resource =" org/ apache/ ibatis/ submitted/ basetest/Mapper.xml " />
37
+ <mapper class =" org. apache. ibatis. submitted. basetest.Mapper " />
38
38
</mappers >
39
39
40
40
</configuration >
You can’t perform that action at this time.
0 commit comments