物理删除:真实删除,将对应数据从数据库中删除,之后查询不到此条被删除数据
1、根据id删除记录,
package com.wzy.bootmtp.test;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wzy.bootmtp.mapper.UserMapper;
import com.wzy.bootmtp.pojo.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Map;
@RunWith(SpringRunner.class)
@SpringBootTest
public class TestSpringBoot {
@Autowired
private UserMapper userMapper;
@Test
public void testDeleteById(){
int result = userMapper.deleteById(2L);
System.out.println(result);
}
}
2、批量删除
package com.wzy.bootmtp.test;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wzy.bootmtp.mapper.UserMapper;
import com.wzy.bootmtp.pojo.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Arrays;
import java.util.Map;
@RunWith(SpringRunner.class)
@SpringBootTest
public class TestSpringBoot {
@Autowired
private UserMapper userMapper;
@Test
public void testDeleteBatchIds() {
int result = userMapper.deleteBatchIds(Arrays.asList(4, 5, 6));
System.out.println(result);
}
}