insert方法是使用所有的属性作为字段使用
@Test
public void testInsert() {
User record=new User();
record.setName("sansan");
// 使用所有的属性作为字段使用
this.newUserMapper.insert(record);
}
2017-08-03 15:06:03,946 [main] [cn.itcast.mybatis.mapper.NewUserMapper.insert]-[DEBUG] ==> Preparing: INSERT INTO tb_user (AGE,USER_NAME,ID,NAME,BIRTHDAY,SEX,PASSWORD,UPDATED,CREATED) VALUES ( ?,?,?,?,?,?,?,?,? )
2017-08-03 15:06:03,973 [main] [cn.itcast.mybatis.mapper.NewUserMapper.insert]-[DEBUG] ==> Parameters: null, null, null, sansan(String), null, null, null, null, null
2017-08-03 15:06:04,010 [main] [cn.itcast.mybatis.mapper.NewUserMapper.insert]-[DEBUG] <== Updates: 1
2017-08-03 15:06:04,014 [main] [cn.itcast.mybatis.mapper.NewUserMapper.insert!selectKey]-[DEBUG] ==> Executing: SELECT LAST_INSERT_ID()
2017-08-03 15:06:04,025 [main] [cn.itcast.mybatis.mapper.NewUserMapper.insert!selectKey]-[DEBUG] <== Total: 1
insertSelective插入数据,使用不为null的属性作为字段使用
@Test
public void testInsertSelective() {
User record=new User();
record.setName("test_insertSelective");
// 插入数据,使用不为null的属性作为字段使用
this.newUserMapper.insertSelective(record);
}
结果:
2017-08-03 14:41:30,406 [main] [cn.itcast.mybatis.mapper.NewUserMapper.insertSelective]-[DEBUG] ==> Preparing: INSERT INTO tb_user ( ID,NAME ) VALUES ( ?,? )
2017-08-03 14:41:30,434 [main] [cn.itcast.mybatis.mapper.NewUserMapper.insertSelective]-[DEBUG] ==> Parameters: null, test_insertSelective(String)
2017-08-03 14:41:30,477 [main] [cn.itcast.mybatis.mapper.NewUserMapper.insertSelective]-[DEBUG] <== Updates: 1
2017-08-03 14:41:30,481 [main] [cn.itcast.mybatis.mapper.NewUserMapper.insertSelective!selectKey]-[DEBUG] ==> Executing: SELECT LAST_INSERT_ID()
2017-08-03 14:41:30,493 [main] [cn.itcast.mybatis.mapper.NewUserMapper.insertSelective!selectKey]-[DEBUG] <== Total: 1