Dynamic Placeholder substitution in properties in java

后端 未结 6 795
死守一世寂寞
死守一世寂寞 2020-12-01 04:49

I wanted to substitute the placeholder dynamically in properties in a java application. Like

 WelcomeMessage=Welcome Mr. {firstName} {lastName} !!!
<         


        
6条回答
  •  甜味超标
    2020-12-01 05:19

    Another option is adding Apache FreeMarker with no dependencies and define template as:

    Welcome Mr. ${firstName} ${lastName} !!!
    

    Apache FreeMarker™ is a template engine: a Java library to generate text output (HTML web pages, e-mails, configuration files, source code, etc.) based on templates and changing data. Templates are written in the FreeMarker Template Language (FTL), which is a simple, specialized language

    You can use StringTemplateLoader to load template using String

    you can create a StringTemplateLoader and add each template to it:

提交回复
热议问题