当前使用版本(必填,否则不予处理)

V3.5.3.1

该问题是如何引起的?(确定最新版也有问题再提!!!)

公司那帮坑货不给开SqlRunner,但是我又要执行动态SQL,且不在mapper中显示${sql},否则会报代码漏洞。我只能拷贝SqlRunner的初始化代码到我自己的代码中,然后自己注册一个MappedStatement,通过这个MappedStatement来进行动态SQL查询。 由于原生的SqlRunner只能返回一个Map类型让我十分火大,且泛型失效,即使那帮坑货帮我开了SqlRunner也不好用,所以我只能自己写一个类似于SqlRunner的动态MappedStatement。但是执行却报错了,原因是InterceptorIgnoreHelper中第143行: ignoreStrategy = IGNORE_STRATEGY_CACHE.get(id.substring(0, id.lastIndexOf(StringPool.DOT))); 没有判断MappedStatement的id中是否存在.号,就去substring了,导致了Cause: java.lang.StringIndexOutOfBoundsException: String index out of range: -1

因此只需要多加一个DOT符号判断是否存在即可,如果不存在,就别substring了,直接跳过即可

重现步骤(如果有就写完整)

MyBatis-Plus 自定义MappedStatement的id中如果不存在.号,则InterceptorIgnoreHelper会报错

` public DataVo testSql(HashMap map) { String sql = map.get("sql"); String rawSqlId = "rawSql";

    Configuration configuration = sqlSessionFactory.getConfiguration();
    LanguageDriver languageDriver = configuration.getDefaultScriptingLanguageInstance();
    SqlSource sqlSource = languageDriver.createSqlSource(configuration, ISqlRunner.SQL_SCRIPT, SysUserEntity.class);
    MappedStatement ms = new MappedStatement.Builder(configuration, rawSqlId, sqlSource, SqlCommandType.SELECT)
            .resultMaps(new ArrayList<ResultMap>() {
                {
                    add(new ResultMap.Builder(configuration, "testSqlResultMap", SysUserEntity.class, new ArrayList<>(0))
                            .build());
                }
            }).build();
    configuration.addMappedStatement(ms);

    SqlSession sqlSession = sqlSession();
    List<SysUserEntity> selectList = sqlSession.selectList(rawSqlId, sql);
    for (SysUserEntity sysUserEntity : selectList) {
        Long id = sysUserEntity.getId();
        log.info("id is {} name is {}", id, sysUserEntity.getUsername());
    }
    return success(selectList);
}

`

报错信息

org.apache.ibatis.exceptions.PersistenceException:

Error querying database. Cause: java.lang.StringIndexOutOfBoundsException: String index out of range: -1

Cause: java.lang.StringIndexOutOfBoundsException: String index out of range: -1

MyBatis-Plus 自定义MappedStatement的id中如果不存在.号,则InterceptorIgnoreHelper会报错

63474f6e5d43fc6989fcddf352cd78d

Comment From: huayanYu

请走PR.

Comment From: qmdx

请关注版本发布 https://github.com/baomidou/mybatis-plus/commit/cd7d4ec14e908d0c760622184b1209c9d6516215