类 ScriptTemplateConfigurer
- 所有已实现的接口:
ScriptTemplateConfig
ScriptTemplateConfig for creating
a ScriptEngine for use in a web application.
// Add the following to an @Configuration class
@Bean
public ScriptTemplateConfigurer mustacheConfigurer() {
ScriptTemplateConfigurer configurer = new ScriptTemplateConfigurer();
configurer.setEngineName("nashorn");
configurer.setScripts("mustache.js");
configurer.setRenderObject("Mustache");
configurer.setRenderFunction("render");
return configurer;
}
NOTE: It is possible to use non thread-safe script engines with
templating libraries not designed for concurrency, like Handlebars or React running on
Nashorn, by setting the sharedEngine property to false.
- 从以下版本开始:
- 4.0
- 作者:
- Sebastien Deleuze
- 另请参阅:
-
字段概要
字段 -
构造器概要
构造器构造器说明Default constructor.ScriptTemplateConfigurer(String engineName) Create a new ScriptTemplateConfigurer using the given engine name. -
方法概要
修饰符和类型方法说明Return the charset used to read script and template files.Return the content type to use for the response.Return theScriptEngineto use by the views.Return the engine name that will be used to instantiate theScriptEngine.Return the engine supplier that will be used to instantiate theScriptEngine.Return the render function name (optional).Return the object where the render function belongs (optional).Return the resource loader path(s) via a Framework resource location.String[]Return the scripts to be loaded by the script engine (library or user provided).Return whether to use a shared engine for all threads or whether to create thread-local engine instances for each thread.voidsetCharset(Charset charset) Set the charset used to read script and template filesvoidsetContentType(String contentType) Set the content type to use for the responsevoidsetEngine(ScriptEngine engine) Set theScriptEngineto use by the view.voidsetEngineName(String engineName) Set the engine name that will be used to instantiate theScriptEngine.voidsetEngineSupplier(Supplier<ScriptEngine> engineSupplier) Set theScriptEnginesupplier to use by the view, usually used withsetSharedEngine(Boolean)set tofalse.voidsetRenderFunction(String renderFunction) Set the render function name (optional).voidsetRenderObject(String renderObject) Set the object where the render function belongs (optional).voidsetResourceLoaderPath(String resourceLoaderPath) Set the resource loader path(s) via a Framework resource location.voidsetScripts(String... scriptNames) Set the scripts to be loaded by the script engine (library or user provided).voidsetSharedEngine(Boolean sharedEngine) When set tofalse, use thread-localScriptEngineinstances instead of one single shared instance.
-
字段详细资料
-
engine
-
engineSupplier
-
engineName
-
scripts
-
renderObject
-
renderFunction
-
contentType
-
charset
-
resourceLoaderPath
-
-
构造器详细资料
-
ScriptTemplateConfigurer
public ScriptTemplateConfigurer()Default constructor. -
ScriptTemplateConfigurer
Create a new ScriptTemplateConfigurer using the given engine name.
-
-
方法详细资料
-
setEngine
Set theScriptEngineto use by the view. IfrenderFunctionis specified, the script engine must implementInvocable. You must defineengineorengineName, not both.When the
sharedEngineflag is set tofalse, you should not specify the script engine with this setter, but withsetEngineName(String)orsetEngineSupplier(Supplier)since it implies multiple lazy instantiations of the script engine. -
getEngine
从接口复制的说明:ScriptTemplateConfigReturn theScriptEngineto use by the views.- 指定者:
getEngine在接口中ScriptTemplateConfig
-
setEngineSupplier
Set theScriptEnginesupplier to use by the view, usually used withsetSharedEngine(Boolean)set tofalse. IfrenderFunctionis specified, the script engine must implementInvocable. You must either defineengineSupplier,engineorengineName. -
getEngineSupplier
从接口复制的说明:ScriptTemplateConfigReturn the engine supplier that will be used to instantiate theScriptEngine.- 指定者:
getEngineSupplier在接口中ScriptTemplateConfig
-
setEngineName
Set the engine name that will be used to instantiate theScriptEngine. IfrenderFunctionis specified, the script engine must implementInvocable. You must defineengineorengineName, not both. -
getEngineName
从接口复制的说明:ScriptTemplateConfigReturn the engine name that will be used to instantiate theScriptEngine.- 指定者:
getEngineName在接口中ScriptTemplateConfig
-
setScripts
Set the scripts to be loaded by the script engine (library or user provided). SinceresourceLoaderPathdefault value is "classpath:", you can load easily any script available on the classpath.For example, in order to use a JavaScript library available as a WebJars dependency and a custom "render.js" file, you should call
configurer.setScripts("/META-INF/resources/webjars/library/version/library.js", "com/myproject/script/render.js");. -
getScripts
从接口复制的说明:ScriptTemplateConfigReturn the scripts to be loaded by the script engine (library or user provided).- 指定者:
getScripts在接口中ScriptTemplateConfig
-
setRenderObject
Set the object where the render function belongs (optional). For example, in order to callMustache.render(),renderObjectshould be set to"Mustache"andrenderFunctionto"render". -
getRenderObject
从接口复制的说明:ScriptTemplateConfigReturn the object where the render function belongs (optional).- 指定者:
getRenderObject在接口中ScriptTemplateConfig
-
setRenderFunction
Set the render function name (optional). If not specified, the script templates will be evaluated withScriptEngine.eval(String, Bindings).This function will be called with the following parameters:
String template: the template contentMap model: the view modelRenderingContext context: the rendering context (since 5.0)
- 另请参阅:
-
getRenderFunction
从接口复制的说明:ScriptTemplateConfigReturn the render function name (optional). If not specified, the script templates will be evaluated withScriptEngine.eval(String, Bindings).- 指定者:
getRenderFunction在接口中ScriptTemplateConfig
-
setContentType
Set the content type to use for the response. (text/htmlby default). -
getContentType
Return the content type to use for the response.- 指定者:
getContentType在接口中ScriptTemplateConfig
-
setCharset
Set the charset used to read script and template files. (UTF-8by default). -
getCharset
从接口复制的说明:ScriptTemplateConfigReturn the charset used to read script and template files.- 指定者:
getCharset在接口中ScriptTemplateConfig
-
setResourceLoaderPath
Set the resource loader path(s) via a Framework resource location. Accepts multiple locations as a comma-separated list of paths. Standard URLs like "file:" and "classpath:" and pseudo URLs are supported as understood by Framework'sResourceLoader. Relative paths are allowed when running in an ApplicationContext.Default is "classpath:".
-
getResourceLoaderPath
从接口复制的说明:ScriptTemplateConfigReturn the resource loader path(s) via a Framework resource location.- 指定者:
getResourceLoaderPath在接口中ScriptTemplateConfig
-