package com.sdut.labex.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * File: MyBatisPlusConfig
 * Created: 2023/6/11
 * Author: springforest
 * Description:
 */
@Configuration
public class MyBatisPlusConfig {
    //分页配置
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        //用于实现防止全表更新和删除操作的拦截器。在执行更新或删除操作时，它会检查SQL语句是否符合预设的条件，如果不符合就会抛出异常，阻止操作的执行。
        interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
        return interceptor;
    }
}
