SqlTemplateParser { public SqlRequest parse(Function<String, Object> propertyMapping) { init(); boolean inPrepare = false; int len = 0; char[] newArr = new char[templateArray.length]; char[] expression = new char[128]; int expressionPos = 0; List<Object> parameters = new ArrayList<>(64); while (next()) { if (isPrepare()) { inPrepare = true; } else if (isPrepareEnd()) { inPrepare = false; parameters.add(propertyMapping.apply(new String(expression, 0, expressionPos))); expressionPos = 0; newArr[len++] = '?'; } else if (inPrepare) { expression[expressionPos++] = symbol; } else { newArr[len++] = symbol; } } if (isPrepareEnd()) { newArr[len++] = '?'; parameters.add(propertyMapping.apply(new String(expression, 0, expressionPos))); } else { newArr[len++] = symbol; } return SqlRequests.prepare(new String(newArr, 0, len), parameters.toArray()); }  SqlRequest parse(Function<String, Object> propertyMapping); SqlRequest parse(); static SqlRequest parse(String template, Object parameter); static SqlRequest parse(String template, Function<String, Object> parameterGetter);  }
@Test public void testParse() { SqlRequest request = SqlTemplateParser.parse("select * from user where name = #{name} and status=1", (__) -> "1234"); assertNotNull(request); assertEquals(request.getSql(),"select * from user where name = ? and status=1"); assertArrayEquals(request.getParameters(),new Object[]{"1234"} ); assertTrue(request instanceof PrepareSqlRequest); assertEquals(((PrepareSqlRequest) request).toNativeSql(),"select * from user where name = '1234' and status=1"); }