当前位置:Gxlcms > 数据库问题 > mybtis plus 3.2.0 SQL注入器的配置

mybtis plus 3.2.0 SQL注入器的配置

时间:2021-07-01 10:21:17 帮助过:33人阅读

class MyMethod extends AbstractMethod { @Override public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) { //自定义sql String sql = "delete from "+tableInfo.getTableName(); //mapper接口的方法名 String method = "deleteAllData"; SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass); return addDeleteMappedStatement(mapperClass,method,sqlSource); } }

二.自定义SQL注入器

@Component
public class MyInjector extends DefaultSqlInjector {
    @Override
    public List<AbstractMethod> getMethodList(Class<?> mapperClass) {
        List<AbstractMethod> methodList = super.getMethodList(mapperClass);
        methodList.add(new MyMethod());
        return methodList;
    }
}

三.在你的Mapper类中添加刚才定义的method

@Repository
public interface UserMapper extends BaseMapper<User> {
    int deleteAllData();
}

四.测试

@Test
    public void testInject(){
        userMapper.deleteAllData();
    }

运行结果:

技术图片

 

mybtis plus 3.2.0 SQL注入器的配置

标签:sql   config   name   mamicode   injector   sql注入   conf   eal   list   

人气教程排行