
就是让你自己写的sql语句和mp的默认sql语句(basemapper中的sql语句)一起启动,就不需要写映射文件了
根据MybatisPlus 的AutoSqlInjector可以自定义各种你想要的sql ,注入到全局中,相当于自定义Mybatisplus 自动注入的方法。
之前需要在xml中进行配置的SQL语句,现在通过扩展AutoSqlInjector 在加载mybatis环境时就注入。

public class FullAll extends AbstractMethod {
    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass,
                                                 TableInfo tableInfo) {
        String sqlMethod = "findAll";
        String sql = "select * from " + tableInfo.getTableName();
        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
        return this.addSelectMappedStatementForTable(mapperClass, sqlMethod, sqlSource, tableInfo);
    }
}public class SqlInjector extends DefaultSqlInjector {
    @Override
    public List<AbstractMethod> getMethodList(Class<?> mapperClass) {
        List<AbstractMethod> methodList = super.getMethodList(mapperClass);
      methodList.add(new FullAll());
        return methodList;
    }
}    @Bean
    public SqlInjector sqlInjector() {
        return new SqlInjector();
    }public interface BaseMapperPlus<T> extends BaseMapper<T> {
    List<T> findAll();
}@Mapper
public interface UserMapper extends BaseMapperPlus<User>
{
}@SpringBootTest
class SpringBootDaoApplicationTests
{
    @Autowired
    UserMapper userMapper;
    @Test
    void test6() {
        List<User> all = userMapper.findAll();
        all.forEach(System.out::println);
    }
}
public interface MyBaseMapper<T> extends BaseMapper<T> {
    int mysqlInsertAllBatch(@Param("list") List<T> batchList);
}演示批量保存使用mysql特有语法:
insert into user(id, name, age) values (1, "a", 17), (2,"b", 18)坑点: