Java String replace the placeholder usage StrSubstitutor

        <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.7</version>
        </dependency>

StrSubstitutor usage

public static void main(String[] args) {        
        Map map = new HashMap();
        map.put("code","267468");
        map.put("product","xxx系统");
        String str1 = "您正在登录${product},验证码为:${code},五分钟内有效,如非本人操作请忽略。";
        StrSubstitutor sb = new StrSubstitutor(map);
        String content = sb.replace(str1);
        System.out.println(content);
}

Output 

您正在登录xxx系统,验证码为:267468,五分钟内有效,如非本人操作请忽略。

 

Published 45 original articles · won praise 51 · views 170 000 +

Guess you like

Origin blog.csdn.net/qq_40162735/article/details/103454194
Recommended