本文整理汇总了Java中org.thymeleaf.templateresolver.TemplateResolver类的典型用法代码示例。如果您正苦于以下问题:Java TemplateResolver类的具体用法?Java TemplateResolver怎么用?Java TemplateResolver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TemplateResolver类属于org.thymeleaf.templateresolver包,在下文中一共展示了TemplateResolver类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: AssetsBundleCustomErrorHandler
import org.thymeleaf.templateresolver.TemplateResolver; //导入依赖的package包/类
public AssetsBundleCustomErrorHandler(Environment environment) {
this.environment = environment;
TemplateResolver templateResolver = new TemplateResolver();
String baseDirForTemplates = System.getProperty("baseDirForTemplates");
if (baseDirForTemplates != null) {
templateResolver.setResourceResolver(new FileResourceResolver());
templateResolver.setPrefix(baseDirForTemplates + "/templates/");
} else {
templateResolver.setResourceResolver(new ThymeleafResourceResolver());
templateResolver.setPrefix("/templates/");
}
templateResolver.setTemplateMode("HTML5");
templateResolver.setCacheable(false);
templateResolver.setCharacterEncoding(StandardCharsets.UTF_8.name());
engine = new TemplateEngine();
engine.setTemplateResolver(templateResolver);
}
示例2: buildIndex
import org.thymeleaf.templateresolver.TemplateResolver; //导入依赖的package包/类
/**
* Builds index.html file. This file contains table with links to validation
* results.
*/
private static void buildIndex() {
try {
Collections.sort(results);
FileWriter writer = new FileWriter(new File("out", "index.html"));
TemplateEngine templateEngine = new TemplateEngine();
TemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setPrefix("resources/");
templateResolver.setSuffix(".html");
templateEngine.setTemplateResolver(templateResolver);
Context ctx = new Context();
ctx.setVariable("results", results);
templateEngine.process("index-template", ctx, writer);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
示例3: init
import org.thymeleaf.templateresolver.TemplateResolver; //导入依赖的package包/类
/**
* Configures engine and template resolving.
*/
@Override
public void init(@SuppressWarnings("rawtypes") NamedList args) {
checkNotNull(args);
this.configuration = SolrParams.toSolrParams(args);
// configure template resolver
templateResolver = new TemplateResolver();
templateResolver.setResourceResolver(resourceResolver);
templateResolver.setCharacterEncoding("utf-8");
templateResolver.setTemplateMode(configuration.get("tl.templateMode", "XHTML"));
templateResolver.setSuffix(configuration.get("tl.suffix", ".html"));
if (configuration.get("tl.cacheTtlMs") != null) {
templateResolver.setCacheTTLMs(Long.parseLong(configuration.get("tl.cacheTTLMs")));
} else {
templateResolver.setCacheTTLMs(TimeUnit.HOURS.toMillis(1l));
}
if (configuration.get("tl.locale") != null) {
locale = Locale.forLanguageTag(configuration.get("tl.locale"));
}
layoutDialect = new LayoutDialect();
}
示例4: overrideCharacterEncoding
import org.thymeleaf.templateresolver.TemplateResolver; //导入依赖的package包/类
@Test
public void overrideCharacterEncoding() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
"spring.thymeleaf.encoding:UTF-16");
this.context.register(ThymeleafAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
this.context.getBean(TemplateEngine.class).initialize();
ITemplateResolver resolver = this.context.getBean(ITemplateResolver.class);
assertThat(resolver instanceof TemplateResolver).isTrue();
assertThat(((TemplateResolver) resolver).getCharacterEncoding())
.isEqualTo("UTF-16");
ThymeleafViewResolver views = this.context.getBean(ThymeleafViewResolver.class);
assertThat(views.getCharacterEncoding()).isEqualTo("UTF-16");
assertThat(views.getContentType()).isEqualTo("text/html;charset=UTF-16");
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:17,代码来源:ThymeleafAutoConfigurationTests.java
示例5: createDefaultTemplateResolver
import org.thymeleaf.templateresolver.TemplateResolver; //导入依赖的package包/类
private static TemplateResolver createDefaultTemplateResolver(String prefix, String suffix) {
TemplateResolver defaultTemplateResolver = new TemplateResolver();
defaultTemplateResolver.setTemplateMode(DEFAULT_TEMPLATE_MODE);
defaultTemplateResolver.setPrefix(
prefix != null ? prefix : DEFAULT_PREFIX
);
defaultTemplateResolver.setSuffix(
suffix != null ? suffix : DEFAULT_SUFFIX
);
//defaultTemplateResolver.setCacheable(false);
defaultTemplateResolver.setCacheTTLMs(DEFAULT_CACHE_TTL_MS);
defaultTemplateResolver.setResourceResolver(new FileResourceResolver());
return defaultTemplateResolver;
}
示例6: defaultTemplateResolver
import org.thymeleaf.templateresolver.TemplateResolver; //导入依赖的package包/类
@Bean
public TemplateResolver defaultTemplateResolver() {
TemplateResolver resolver = new TemplateResolver();
resolver.setResourceResolver(thymeleafResourceResolver());
resolver.setPrefix(this.properties.getPrefix());
resolver.setSuffix(this.properties.getSuffix());
resolver.setTemplateMode(this.properties.getMode());
if (this.properties.getEncoding() != null) {
resolver.setCharacterEncoding(this.properties.getEncoding().name());
}
resolver.setCacheable(this.properties.isCache());
Integer order = this.properties.getTemplateResolverOrder();
if (order != null) {
resolver.setOrder(order);
}
return resolver;
}
示例7: createThymeleaf
import org.thymeleaf.templateresolver.TemplateResolver; //导入依赖的package包/类
@Bean
public ThymeleafTemplateEngine createThymeleaf() {
boolean cachingEnabled = env.getProperty("jbakery.thymeleaf.cachingEnabled", Boolean.class, false);
TemplateResolver templateResolver = new TemplateResolver();
templateResolver.setResourceResolver(new FileResourceResolver());
templateResolver.setPrefix("templates/");
templateResolver.setTemplateMode("HTML5");
templateResolver.setSuffix(".html");
templateResolver.setCacheable(cachingEnabled);
templateResolver.addTemplateAlias("", "/index");
templateResolver.addTemplateAlias("/", "/index");
ThymeleafTemplateEngine engine = ThymeleafTemplateEngine.create()
.setMode(StandardTemplateModeHandlers.HTML5.getTemplateModeName());
// enable layout
engine.getThymeleafTemplateEngine().addDialect(new LayoutDialect());
engine.getThymeleafTemplateEngine().setTemplateResolver(templateResolver);
return engine;
}
示例8: defaultTemplateResolver
import org.thymeleaf.templateresolver.TemplateResolver; //导入依赖的package包/类
@Bean
public ITemplateResolver defaultTemplateResolver() {
final TemplateResolver resolver = new TemplateResolver();
resolver.setResourceResolver(thymeleafResourceResolver());
resolver.setPrefix(this.environment.getProperty("prefix", DEFAULT_PREFIX));
resolver.setSuffix(this.environment.getProperty("suffix", DEFAULT_SUFFIX));
resolver.setTemplateMode(this.environment.getProperty("mode", "HTML5"));
resolver.setCharacterEncoding(this.environment.getProperty("encoding", "UTF-8"));
final Boolean cache = this.environment.getProperty("cache", Boolean.class, true);
resolver.setCacheable(cache);
if (!cache) {
resolver.setCacheTTLMs(0L);
}
return resolver;
}
示例9: getFileSystemResolver
import org.thymeleaf.templateresolver.TemplateResolver; //导入依赖的package包/类
@Bean
public TemplateResolver getFileSystemResolver() {
TemplateResolver resolver = new TemplateResolver();
resolver.setPrefix("");
resolver.setSuffix("");
resolver.setCacheable(false);
resolver.setOrder(1);
resolver.setResourceResolver(new FileResourceResolver());
return resolver;
}
示例10: templateEngine
import org.thymeleaf.templateresolver.TemplateResolver; //导入依赖的package包/类
@Bean
@Description("Thymeleaf template engine with Spring integration")
public SpringTemplateEngine templateEngine(final TemplateResolver templateResolver)
throws Exception {
SpringTemplateEngine engine = new SpringTemplateEngine();
engine.setTemplateResolver(templateResolver);
engine.addDialect(new SpringSecurityDialect());
engine.addDialect(new LayoutDialect(new GroupingStrategy()));
engine.afterPropertiesSet();
return engine;
}