本文整理匯總了Java中org.thymeleaf.templateresolver.ClassLoaderTemplateResolver.setCacheTTLMs方法的典型用法代碼示例。如果您正苦於以下問題:Java ClassLoaderTemplateResolver.setCacheTTLMs方法的具體用法?Java ClassLoaderTemplateResolver.setCacheTTLMs怎麽用?Java ClassLoaderTemplateResolver.setCacheTTLMs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.thymeleaf.templateresolver.ClassLoaderTemplateResolver
的用法示例。
在下文中一共展示了ClassLoaderTemplateResolver.setCacheTTLMs方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testTemplate
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //導入方法依賴的package包/類
@Test
public void testTemplate() throws Exception {
ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setPrefix("org/restlet/ext/thymeleaf/");
templateResolver.setSuffix(".html");
templateResolver.setCacheTTLMs(3600000L);
final Map<String, Object> map = new TreeMap<>();
map.put("welcome", "Hello, world");
final String result = new TemplateRepresentation("test",
TemplateRepresentation.createTemplateEngine(templateResolver),
Locale.getDefault(), map, MediaType.TEXT_PLAIN).getText();
assertTrue(result.contains("Hello, world"));
}
示例2: testThymeleafTemplate
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //導入方法依賴的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);
}
示例3: testApp
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //導入方法依賴的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);
}
示例4: createDefaultTemplateResolver
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //導入方法依賴的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;
}
示例5: createTemplateResolver
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //導入方法依賴的package包/類
/**
* Returns a new instance of {@link ITemplateResolver} with default
* configuration (XHTML template model, templates located inside
* "/WEB-INF/templates/", suffixed by ".html".
*
* @return A new instance of {@link ITemplateResolver}.
*/
public static ITemplateResolver createTemplateResolver() {
ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
// XHTML is the default mode, but we will set it anyway for better
// understanding of code
templateResolver.setTemplateMode("XHTML");
// This will convert "home" to "/WEB-INF/templates/home.html"
templateResolver.setPrefix("/WEB-INF/templates/");
templateResolver.setSuffix(".html");
// Set template cache TTL to 1 hour. If not set, entries would live in
// cache until expelled by LRU
templateResolver.setCacheTTLMs(3600000L);
return templateResolver;
}
示例6: ThymeleafTemplateProcessorImpl
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //導入方法依賴的package包/類
@Inject
public ThymeleafTemplateProcessorImpl() {
final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setTemplateMode(HTML);
templateResolver.setSuffix(".html");
templateResolver.setCacheTTLMs(3600000L);
this.templateEngine = new TemplateEngine();
this.templateEngine.setTemplateResolver(templateResolver);
}
示例7: createDefaultTemplateResolver
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //導入方法依賴的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;
}
示例8: createEngine
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //導入方法依賴的package包/類
private static TemplateEngine createEngine()
{
ClassLoaderTemplateResolver resolver = new ClassLoaderTemplateResolver();
resolver.setTemplateMode("HTML5");
resolver.setCacheTTLMs(60 * 1000L);
resolver.setCacheable(true);
TemplateEngine engine = new TemplateEngine();
engine.setTemplateResolver(resolver);
return engine;
}