1
접두어 만 사용하여 표시된 문자열의 변수를 대체하기 위해 Apache Commons Lang의 StrSubstitutor
을 사용하려고합니다. SQL 쿼리에서 :
이라는 이름의 매개 변수를 markjed와 같이 사용합니다.빈 변수 접미어와 함께 StrSubstitutor를 어떻게 사용할 수 있습니까?
다음 코드는 제가 사용하고있는 코드입니다. 작동하지 않습니다.
import com.google.common.collect.ImmutableMap;
import org.apache.commons.lang3.text.StrMatcher;
import org.apache.commons.lang3.text.StrSubstitutor;
Map<String,String> m = ImmutableMap.of("a", 1);
StrSubstitutor strSubstitutor = new StrSubstitutor(m)
.setVariablePrefix(":")
.setVariableSuffix("");
System.out.println(strSubstitutor.replace("select a from t where a = :a"));
// expect select a from t where a = 1
어떻게해야할까요?
사용자 정의 StrMatcher
을 구현하려고하지만 아직 실패했습니다. 어느 누구도 이전에 해본 경험이 있으며 경험을 공유 할 수 있습니까?