@Test publicvoidtestInsertFill(){ User user = new User(); user.setName("张四"); user.setUserName("zhangsi"); user.setPassword("123123"); user.setAge(30); user.setEmail("zhangsi@itast.cn");
int result = this.userMapper.insert(user); System.out.println("result = " + result); }
输出
1 2 3 4 5 6 7 8 9 10
Time:9 ms - ID:com.coconutnut.demo.mapper.UserMapper.insert Execute SQL: INSERT INTO tb_user ( user_name, password, name, age, email, version ) VALUES ( 'zhangsi', '123123', '张四', 30, 'zhangsi@itast.cn', 1 )
result = 1
逻辑删除
将数据标记为删除,而并非真正删除
查询时需要携带状态条件,确保被标记的数据不被查询到
修改表结构
为tb_user表增加deleted字段,用于表示数据是否被删除,1代表删除,0代表未删除
1 2
ALTERTABLE `tb_user` ADDCOLUMN `deleted` int(1) NULLDEFAULT0 COMMENT '1代表删除,0代表未删除' AFTER `version`;
@Test publicvoidtestInsert(){ User user = new User(); user.setName("张五"); user.setAge(30); user.setPassword("123456"); user.setUserName("zhangwu"); user.setEmail("zhangwu@itcast.cn"); user.setSex(SexEnum.WOMAN);