File tree Expand file tree Collapse file tree 5 files changed +12
-10
lines changed
mapper/src/test/java/io/mybatis/mapper Expand file tree Collapse file tree 5 files changed +12
-10
lines changed Original file line number Diff line number Diff line change 2727import io .mybatis .provider .Caching ;
2828import org .apache .ibatis .annotations .InsertProvider ;
2929import org .apache .ibatis .annotations .Lang ;
30- import org .apache .ibatis .annotations .Options ;
3130import org .apache .ibatis .annotations .SelectKey ;
3231
3332public interface UserAutoMapper extends
@@ -38,11 +37,6 @@ public interface UserAutoMapper extends
3837 ListMapper <UserAuto >,
3938 SumMapper <UserAuto > {
4039
41- @ Override
42- @ Lang (Caching .class )
43- @ Options (useGeneratedKeys = true , keyProperty = "id" )
44- @ InsertProvider (type = EntityProvider .class , method = "insert" )
45- int insert (UserAuto entity );
4640
4741 @ Override
4842 @ Lang (Caching .class )
Original file line number Diff line number Diff line change 2525import io .mybatis .mapper .list .ListMapper ;
2626import io .mybatis .mapper .model .User ;
2727import io .mybatis .provider .Caching ;
28- import org .apache .ibatis .annotations .*;
28+ import org .apache .ibatis .annotations .InsertProvider ;
29+ import org .apache .ibatis .annotations .Lang ;
30+ import org .apache .ibatis .annotations .SelectKey ;
31+ import org .apache .ibatis .annotations .SelectProvider ;
2932
3033import java .util .List ;
3134
@@ -39,7 +42,6 @@ public interface UserMapper extends
3942
4043 @ Override
4144 @ Lang (Caching .class )
42- @ Options (useGeneratedKeys = true , keyProperty = "id" )
4345 @ InsertProvider (type = EntityProvider .class , method = "insert" )
4446 int insert (User entity );
4547
Original file line number Diff line number Diff line change @@ -40,6 +40,12 @@ public void testInsert() {
4040 entityMapper .insert (user );
4141 Assert .assertNotNull (user .getId ());
4242 entityMapper .selectByPrimaryKey (user .getId ());
43+
44+ user = new User ();
45+ user .setUserName ("测试" );
46+ entityMapper .insert (user );
47+ Assert .assertNotNull (user .getId ());
48+ entityMapper .selectByPrimaryKey (user .getId ());
4349 sqlSession .rollback ();
4450 } finally {
4551 //不要忘记关闭sqlSession
Original file line number Diff line number Diff line change 2626 }
2727)
2828public class User {
29- @ Entity .Column (id = true )
29+ @ Entity .Column (id = true , useGeneratedKeys = true )
3030 private Long id ;
3131 @ Entity .Column ("name" )
3232 private String userName ;
Original file line number Diff line number Diff line change 2727
2828@ Entity .Table (value = "user_auto" , autoResultMap = true )
2929public class UserAuto {
30- @ Entity .Column (id = true )
30+ @ Entity .Column (id = true , useGeneratedKeys = true )
3131 private Long id ;
3232 @ Entity .Column ("user_name" )
3333 private String name ;
You can’t perform that action at this time.
0 commit comments