标签:sql config name mamicode injector sql注入 conf eal list
一.创建定义方法的类
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(); }
运行结果:
标签:sql config name mamicode injector sql注入 conf eal list
原文地址:https://www.cnblogs.com/wwjj4811/p/12623844.html