Class StTemplateRenderer
java.lang.Object
org.springframework.ai.template.st.StTemplateRenderer
- All Implemented Interfaces:
BiFunction<String,,Map<String, Object>, String> TemplateRenderer
Renders a template using the StringTemplate (ST) v4 library.
This renderer allows customization of delimiters, validation behavior when template variables are missing, and how StringTemplate's built-in functions are handled during validation.
Use the builder() to create and configure instances.
Thread safety: This class is safe for concurrent use. Each call to
apply(String, Map) creates a new StringTemplate instance, and no mutable state
is shared between threads.
- Since:
- 1.0.0
- Author:
- Thomas Vitale, Sun Yuhan
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for configuring and creatingStTemplateRendererinstances. -
Constructor Summary
ConstructorsConstructorDescriptionStTemplateRenderer(char startDelimiterToken, char endDelimiterToken, ValidationMode validationMode, boolean validateStFunctions) Constructs a newStTemplateRendererwith the specified delimiter tokens, validation mode, and function validation flag. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.function.BiFunction
andThen
-
Constructor Details
-
StTemplateRenderer
public StTemplateRenderer(char startDelimiterToken, char endDelimiterToken, ValidationMode validationMode, boolean validateStFunctions) Constructs a newStTemplateRendererwith the specified delimiter tokens, validation mode, and function validation flag.- Parameters:
startDelimiterToken- the character used to denote the start of a template variable (e.g., '{')endDelimiterToken- the character used to denote the end of a template variable (e.g., '}')validationMode- the mode to use for template variable validation; must not be nullvalidateStFunctions- whether to validate StringTemplate functions in the template
-
-
Method Details
-
apply
- Specified by:
applyin interfaceBiFunction<String,Map<String, Object>, String> - Specified by:
applyin interfaceTemplateRenderer
-
builder
-