package com.hxd.sqlAbout;
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;
public class DeleteAllMethod extends AbstractMethod {
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
String sql="delete from "+tableInfo.getTableName();
String method="deleteAll";
SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
return addDeleteMappedStatement(mapperClass,method,sqlSource);
}
}
package com.hxd.sqlAbout;
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import com.baomidou.mybatisplus.core.injector.methods.*;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class SqlInjector extends DefaultSqlInjector {
@Override
public List<AbstractMethod> getMethodList(Class<?> mapperClass) {
List<AbstractMethod> methodList = super.getMethodList(mapperClass);
methodList.add(new DeleteAllMethod());
return methodList;
}
}
package com.hxd.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hxd.pojo.User;
import org.springframework.stereotype.Repository;
@Repository
public interface UserMapper extends BaseMapper<User> {
int deleteAll();
}
@RequestMapping("deletealluser")
public String deleteAllUser(){
int i= userService.deleteAllUser();
if(i>0){
return "删除所有成功";
}
return "删除所有失败";
}
public int deleteAllUser() {
int i = userMapper.deleteAll();
return i;
}