1. package com.example.aninbatis.sqlsource;
    2. import com.example.aninbatis.utils.GenericTokenParser;
    3. import com.example.aninbatis.utils.ParameterMappingTokenHandler;
    4. /**
    5. * 将DynamicSqlSource和RawSqlSource解析成StaticSqlSource
    6. * StaticSqlSource存储的就是只有?的sql语句以及相应的sql信息
    7. */
    8. public class SqlSourceParser {
    9. public SqlSource parse(String sqlText) {
    10. ParameterMappingTokenHandler tokenHandler = new ParameterMappingTokenHandler();
    11. GenericTokenParser tokenParser = new GenericTokenParser("#{", "}", tokenHandler);
    12. // tokenParser.parse(sqlText)参数是未处理的,返回值是已处理的(没有${}和#{})
    13. String sql = tokenParser.parse(sqlText);
    14. return new StaticSqlSource(sql, tokenHandler.getParameterMappings());
    15. }
    16. }