本文整理匯總了Java中org.thymeleaf.templatemode.TemplateMode類的典型用法代碼示例。如果您正苦於以下問題:Java TemplateMode類的具體用法?Java TemplateMode怎麽用?Java TemplateMode使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TemplateMode類屬於org.thymeleaf.templatemode包,在下文中一共展示了TemplateMode類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: mailPreviewTemplateResolver
import org.thymeleaf.templatemode.TemplateMode; //導入依賴的package包/類
/**
* Template resolver for mail preview pages that include email templates (maybe I could just use emailTemplateResolver())
* @return
*/
public ITemplateResolver mailPreviewTemplateResolver() {
// ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
resolver.setApplicationContext(applicationContext);
resolver.setPrefix("/WEB-INF/classes/" + YadaConstants.EMAIL_TEMPLATES_PREFIX);
// The final slash is not needed because all email template paths must start with "/email/" as specified in the "patterns.add()" statement below
// resolver.setPrefix("/WEB-INF/classes/" + YadaConstants.EMAIL_TEMPLATES_PREFIX + "/");
/* From the tutorial:
When several template resolvers are applied, it is recommended to specify patterns
for each template resolver so that Thymeleaf can quickly discard those template resolvers
that are not meant to resolve the template, enhancing performance. Doing this is not a
requirement, but a recommendation
*/
Set<String> patterns = new HashSet<>();
patterns.add("/email/*"); // Start with "/email/"
resolver.setResolvablePatterns(patterns);
resolver.setSuffix(".html");
resolver.setCharacterEncoding("UTF-8");
resolver.setTemplateMode(TemplateMode.HTML);
resolver.setCacheable(config.isProductionEnvironment());
resolver.setOrder(20);
return resolver;
}
示例2: configure
import org.thymeleaf.templatemode.TemplateMode; //導入依賴的package包/類
protected void configure() {
if (viewResolverConfiguration != null) {
org.thymeleaf.TemplateEngine engine = new org.thymeleaf.TemplateEngine();
Set<ITemplateResolver> resolvers = new HashSet<>();
for (String prefix : viewResolverConfiguration.getPrefixes()) {
ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setPrefix(prefix);
templateResolver.setSuffix(viewResolverConfiguration.getSuffix());
templateResolver.setTemplateMode(TemplateMode.HTML);
templateResolver.setCheckExistence(true);
resolvers.add(templateResolver);
}
engine.setTemplateResolvers(configureTemplateResolvers(resolvers));
this.templateEngine = engine;
configured = true;
}
}
示例3: yadaTemplateResolver
import org.thymeleaf.templatemode.TemplateMode; //導入依賴的package包/類
@Bean
public ClassLoaderTemplateResolver yadaTemplateResolver() {
ClassLoaderTemplateResolver resolver = new ClassLoaderTemplateResolver();
// Relative paths never work, with or without trailing slash, so better to be consistent without and always use "absolute" paths [xtian]
resolver.setPrefix(YadaConstants.YADA_VIEW_PREFIX); // Attenzione allo slash finale!
// resolver.setPrefix(YadaConstants.YADA_VIEW_PREFIX + "/"); // Attenzione allo slash finale!
/* From the tutorial:
When several template resolvers are applied, it is recommended to specify patterns
for each template resolver so that Thymeleaf can quickly discard those template resolvers
that are not meant to resolve the template, enhancing performance. Doing this is not a
requirement, but a recommendation
*/
Set<String> patterns = new HashSet<>();
patterns.add("/yada/*"); // Start with "yada"
resolver.setResolvablePatterns(patterns);
resolver.setSuffix(".html");
resolver.setCharacterEncoding("UTF-8");
resolver.setTemplateMode(TemplateMode.HTML);
resolver.setCacheable(config.isProductionEnvironment());
resolver.setOrder(10);
return resolver;
}
示例4: webTemplateResolver
import org.thymeleaf.templatemode.TemplateMode; //導入依賴的package包/類
@Bean
public ITemplateResolver webTemplateResolver() {
// ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
resolver.setApplicationContext(applicationContext);
// Relative paths never work, with or without trailing slash, so better to be consistent without and always use "absolute" paths [xtian]
resolver.setPrefix("/WEB-INF/views");
// resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".html");
// Set<String> patterns = new HashSet<>();
// patterns.add("^(?!/yada/).*"); // Do not start with "yada" - DOES NOT WORK because it doesn't accept a regexp
// resolver.setResolvablePatterns(patterns);
resolver.setCharacterEncoding("UTF-8");
// NB, selecting HTML5 as the template mode.
resolver.setTemplateMode(TemplateMode.HTML);
resolver.setCacheable(config.isProductionEnvironment());
resolver.setOrder(30); // The last one, because it doesn't have any ResolvablePatterns
return resolver;
}
示例5: templateEngine
import org.thymeleaf.templatemode.TemplateMode; //導入依賴的package包/類
@Bean
public SpringTemplateEngine templateEngine() {
SpringTemplateEngine mock = spy(SpringTemplateEngine.class);
final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setOrder(2);
templateResolver.setResolvablePatterns(Collections.singleton("html/*"));
templateResolver.setPrefix("/mail/");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode(TemplateMode.HTML);
templateResolver.setCharacterEncoding("UTF-8");
templateResolver.setCacheable(false);
mock.addTemplateResolver(templateResolver);
final ClassLoaderTemplateResolver templateResolverTxt = new ClassLoaderTemplateResolver();
templateResolverTxt.setOrder(1);
templateResolverTxt.setResolvablePatterns(Collections.singleton("text/*"));
templateResolverTxt.setPrefix("/mail/");
templateResolverTxt.setSuffix(".txt");
templateResolverTxt.setTemplateMode(TemplateMode.TEXT);
templateResolverTxt.setCharacterEncoding("UTF-8");
templateResolverTxt.setCacheable(false);
mock.addTemplateResolver(templateResolverTxt);
return mock;
}
示例6: activate
import org.thymeleaf.templatemode.TemplateMode; //導入依賴的package包/類
@Activate
protected void activate(ComponentContext componentContext) {
BundleTemplateResolver templateResolver = new BundleTemplateResolver(componentContext.getUsingBundle());
templateResolver.setPrefix("views/");
templateResolver.setSuffix(".html");
templateResolver.setCharacterEncoding("UTF-8");
templateResolver.setTemplateMode(TemplateMode.HTML);
// default is cacheable
templateResolver.setCacheable(false);
templateResolver.setOrder(1);
// RK: This is performance intensive OP, need to look into code for a
// better alternative
templateResolver.setCheckExistence(true);
TemplateEngine engine = new TemplateEngine();
engine.addTemplateResolver(templateResolver);
}
示例7: configure
import org.thymeleaf.templatemode.TemplateMode; //導入依賴的package包/類
@Override
public void configure(final Env env, final Config conf, final Binder binder) throws Throwable {
ClassLoaderTemplateResolver resolver = new ClassLoaderTemplateResolver();
boolean cacheable = !env.name().equals("dev");
/** Defaults: */
resolver.setCacheable(cacheable);
resolver.setPrefix(prefix);
resolver.setSuffix(suffix);
resolver.setTemplateMode(TemplateMode.HTML);
TemplateEngine engine = new TemplateEngine();
engine.setTemplateResolver(resolver);
if (callback != null) {
callback.accept(engine, conf);
}
binder.bind(TemplateEngine.class).toInstance(engine);
binder.bind(ITemplateEngine.class).toInstance(engine);
Multibinder.newSetBinder(binder, Renderer.class)
.addBinding()
.toInstance(new ThlEngine(engine, env));
}
示例8: thymeleafTemplateResolver
import org.thymeleaf.templatemode.TemplateMode; //導入依賴的package包/類
@Bean
public SpringResourceTemplateResolver thymeleafTemplateResolver() {
final SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
resolver.setApplicationContext(this.ctx);
resolver.setPrefix("classpath:/templates/");
resolver.setSuffix(".html");
resolver.setTemplateMode(TemplateMode.HTML);
resolver.setCacheable(false);
resolver.setCheckExistence(false);
return resolver;
}
示例9: testThymeleafTemplate
import org.thymeleaf.templatemode.TemplateMode; //導入依賴的package包/類
@Test
@Ignore
public void testThymeleafTemplate() throws IOException, MessagingException {
ClassLoaderTemplateResolver templateResolver =
new ClassLoaderTemplateResolver();
templateResolver.setTemplateMode(TemplateMode.HTML);
templateResolver.setPrefix("/templates/");
templateResolver.setSuffix(".html");
templateResolver.setCacheTTLMs(Long.valueOf(3600000L));
templateResolver.setCharacterEncoding("UTF-8");
templateResolver.setCacheable(true);
TemplateEngine templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
Context ctx = new Context();
ctx.setLocale(Locale.ENGLISH);
ctx.setVariable("username", "ricky");
ctx.setVariable("url", "http://www.thymeleaf.org");
ctx.setVariable("email", "[email protected]");
StringWriter sw = new StringWriter(1024);
templateEngine.process("registry", ctx, sw);
String output = sw.toString();
System.out.println(output);
Mail mail = Mail.newBuilder().from(from,"ricky fung")
.to(to)
.subject("測試郵件[模板郵件-Thymeleaf]")
.html(output)
.build();
client.send(mail);
}
示例10: testApp
import org.thymeleaf.templatemode.TemplateMode; //導入依賴的package包/類
@Test
@Ignore
public void testApp() throws IOException {
//use thymeleaf
ClassLoaderTemplateResolver templateResolver =
new ClassLoaderTemplateResolver();
templateResolver.setTemplateMode(TemplateMode.HTML);
templateResolver.setPrefix("/templates/");
templateResolver.setSuffix(".html");
templateResolver.setCacheTTLMs(Long.valueOf(3600000L));
templateResolver.setCharacterEncoding("UTF-8");
templateResolver.setCacheable(true);
TemplateEngine templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
Context ctx = new Context();
ctx.setLocale(Locale.ENGLISH);
ctx.setVariable("username", "ricky");
ctx.setVariable("url", "http://www.thymeleaf.org");
ctx.setVariable("email", "[email protected]");
StringWriter sw = new StringWriter(1024);
templateEngine.process("registry", ctx, sw);
String output = sw.toString();
System.out.println(output);
}
示例11: templateResolver
import org.thymeleaf.templatemode.TemplateMode; //導入依賴的package包/類
@Bean
ITemplateResolver templateResolver()
{
SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
resolver.setPrefix("/WEB-INF/templates/");
resolver.setSuffix(".html");
resolver.setTemplateMode(TemplateMode.HTML);
//debug
resolver.setCacheable(false);
return resolver;
}
示例12: templateResolver
import org.thymeleaf.templatemode.TemplateMode; //導入依賴的package包/類
private ITemplateResolver templateResolver() {
SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
resolver.setApplicationContext(applicationContext);
resolver.setSuffix(".html");
resolver.setPrefix("/WEB-INF/templates/");
resolver.setTemplateMode(TemplateMode.HTML);
return resolver;
}
示例13: htmlTemplateResolver
import org.thymeleaf.templatemode.TemplateMode; //導入依賴的package包/類
private ITemplateResolver htmlTemplateResolver() {
final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setPrefix("/templates/mail/");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode(TemplateMode.HTML);
templateResolver.setCacheable(false);
return templateResolver;
}
示例14: createDefaultTemplateResolver
import org.thymeleaf.templatemode.TemplateMode; //導入依賴的package包/類
private static ITemplateResolver createDefaultTemplateResolver(String prefix, String suffix) {
final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setTemplateMode(TemplateMode.HTML);
templateResolver.setPrefix(
prefix != null ? prefix : DEFAULT_PREFIX
);
templateResolver.setSuffix(
suffix != null ? suffix : DEFAULT_SUFFIX
);
templateResolver.setCacheTTLMs(DEFAULT_CACHE_TTL_MS);
return templateResolver;
}
示例15: templateResolver
import org.thymeleaf.templatemode.TemplateMode; //導入依賴的package包/類
@Bean
public ITemplateResolver templateResolver() {
SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
resolver.setApplicationContext(applicationContext);
resolver.setPrefix("classpath:/templates");
resolver.setTemplateMode(TemplateMode.TEXT);
return resolver;
}