Java 字符串替换占位符 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 用法

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);
}

输出结果 

您正在登录xxx系统,验证码为:267468,五分钟内有效,如非本人操作请忽略。
发布了45 篇原创文章 · 获赞 51 · 访问量 17万+

猜你喜欢

转载自blog.csdn.net/qq_40162735/article/details/103454194