一.邏輯刪除



配置邏輯刪除的字段時,logic-delete-field字段配置的是邏輯刪除的實體字段名。字段類型可以是boolean和integer。
在java中默認是boolean類型。邏輯已刪除值默認為1,而邏輯未刪除值默認為0。當是1時代表已刪除(1在數據庫表中為true,true從數據庫表中查詢出來為1),是0時代表未刪除(0在數據庫表中為false,false從數據庫表中查詢出來為0)。
二.測試
package com.itheima.mp.service.Impl;import com.itheima.mp.service.IAddressService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import static org.junit.jupiter.api.Assertions.*;@SpringBootTest
class AddressServiceImplTest {@Autowiredprivate IAddressService addressService;@Testvoid removeById() {addressService.removeById(59L);}
}
我們測試removeById方法,刪除id為59的地址,當然這只是邏輯刪除。看一下log日志輸出和數據庫中的字段值變化。

可以看到delete語句變成了update語句,并且deleted=0條件也被加上,即刪除邏輯上未被刪除的。已被刪除的不會再次刪除。

被邏輯刪除后,查詢結果為null(只會查詢deleted?= 0,即沒被邏輯刪除的字段)。
