用mybatis-plus清空teble表数据

时间:2025-03-20 13:27:09

使用 MyBatis-Plus 清空表数据可以使用 IDeleteService#delete 方法。

首先,你需要在你的 Mapper 接口中声明 IDeleteService 接口,如下所示:

public interface YourMapper extends BaseMapper<YourEntity>, IDeleteService<YourEntity> {

}

然后,你就可以在你的代码中使用 delete 方法来清空表数据了,例如:

yourMapper.delete(null);

delete 方法的第一个参数是一个 Wrapper 对象,它可以用来指定删除的条件。如果你想删除所有数据,可以将其设置为 null

注意:该方法会真正的从数据库中删除数据,并且不会进行逻辑删除。因此,请谨慎使用。