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 11/*
2- * Copyright 2009-2012 The MyBatis Team
2+ * Copyright 2009-2013 The MyBatis Team
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -33,7 +33,7 @@ public class BaseTest {
3333
3434 @ BeforeClass
3535 public static void setUp () throws Exception {
36- // create a SqlSessionFactory
36+ // create an SqlSessionFactory
3737 Reader reader = Resources .getResourceAsReader ("org/apache/ibatis/submitted/basetest/mybatis-config.xml" );
3838 sqlSessionFactory = new SqlSessionFactoryBuilder ().build (reader );
3939 reader .close ();
@@ -61,4 +61,18 @@ public void shouldGetAUser() {
6161 }
6262 }
6363
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+
6478}
Original file line number Diff line number Diff line change 1818public interface Mapper {
1919
2020 User getUser (Integer id );
21+ void insertUser (User user );
2122
2223}
Original file line number Diff line number Diff line change 11<?xml version =" 1.0" encoding =" UTF-8" ?>
22<!--
3- Copyright 2009-2012 The MyBatis Team
3+ Copyright 2009-2013 The MyBatis Team
44
55 Licensed under the Apache License, Version 2.0 (the "License");
66 you may not use this file except in compliance with the License.
2121<mapper namespace =" org.apache.ibatis.submitted.basetest.Mapper" >
2222
2323 <select id =" getUser" resultType =" org.apache.ibatis.submitted.basetest.User" >
24- select * from users
24+ select * from users where id = #{id}
2525 </select >
2626
27+ <insert id =" insertUser" >
28+ insert into users values(#{id}, #{name})
29+ </insert >
30+
2731</mapper >
Original file line number Diff line number Diff line change 11<?xml version =" 1.0" encoding =" UTF-8" ?>
22<!--
3- Copyright 2009-2012 The MyBatis Team
3+ Copyright 2009-2013 The MyBatis Team
44
55 Licensed under the Apache License, Version 2.0 (the "License");
66 you may not use this file except in compliance with the License.
3434 </environments >
3535
3636 <mappers >
37- <mapper resource =" org/ apache/ ibatis/ submitted/ basetest/Mapper.xml " />
37+ <mapper class =" org. apache. ibatis. submitted. basetest.Mapper " />
3838 </mappers >
3939
4040</configuration >
You can’t perform that action at this time.
0 commit comments