mybatis-plus實現邏輯刪除
阿新 • • 發佈:2021-01-20
技術標籤:mybatis-plus
一、在表中新增欄位deleted,對應實體類中新增屬性,屬性添加註解。
新增maven
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.1</version>
</dependency>
在基類上新增deleted欄位和註解
@Data
public class BaseTable {
@TableId(type = IdType.ID_WORKER)
private Long id;
@Version
@TableField(fill = FieldFill.INSERT)
private Integer version;
@TableField(fill = FieldFill.INSERT)
private Date createTime;
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateTime;
@TableLogic
private Integer deleted;
}
實體類繼承基類
@Data
@TableName("tb_user")
public class User extends BaseTable{
private String name;
private Integer age;
}
測試:
@DisplayName("Junit5功能測試類")
@SpringBootTest
class SpringMvdApplicationTests {
@Autowired
private UserService userService;
@Autowired
private NewUserMapper userMapper;
//測試邏輯刪除
@Test
public void testDelete() {
userService.removeById(1350351840632295425L);
}
}
結果: