首页 > 数据库技术 > 详细

mybtis plus 3.2.0 SQL注入器的配置

时间:2020-04-03 00:21:42      阅读:75      评论:0      收藏:0      [点我收藏+]

一.创建定义方法的类

public 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注入器的配置

原文:https://www.cnblogs.com/wwjj4811/p/12623844.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!