當前位置: 首頁>>代碼示例>>Java>>正文


Java TemplateMode類代碼示例

本文整理匯總了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;
	}
 
開發者ID:xtianus,項目名稱:yadaframework,代碼行數:28,代碼來源:YadaWebConfig.java

示例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;
    }
}
 
開發者ID:Kentico,項目名稱:delivery-sdk-java,代碼行數:18,代碼來源:ThymeleafTemplateEngine.java

示例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;
	}
 
開發者ID:xtianus,項目名稱:yadaframework,代碼行數:23,代碼來源:YadaWebConfig.java

示例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;
	}
 
開發者ID:xtianus,項目名稱:yadaframework,代碼行數:20,代碼來源:YadaWebConfig.java

示例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;
  }
 
開發者ID:KonkerLabs,項目名稱:konker-platform,代碼行數:27,代碼來源:SpringMailTestConfiguration.java

示例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);
}
 
開發者ID:AdeptJ,項目名稱:adeptj-modules,代碼行數:17,代碼來源:ThymeleafViewEngine.java

示例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));
}
 
開發者ID:jooby-project,項目名稱:jooby,代碼行數:25,代碼來源:Thl.java

示例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;

}
 
開發者ID:hantsy,項目名稱:spring-reactive-sample,代碼行數:14,代碼來源:WebConfig.java

示例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);
}
 
開發者ID:TFdream,項目名稱:okmail,代碼行數:39,代碼來源:OkMailClientTest.java

示例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);
}
 
開發者ID:TFdream,項目名稱:okmail,代碼行數:32,代碼來源:ThymeleafTest.java

示例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;
}
 
開發者ID:scrumtracker,項目名稱:scrumtracker2017,代碼行數:12,代碼來源:ThymeleafConfig.java

示例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;
}
 
開發者ID:ArturWisniewski,項目名稱:ToDoApp-Spring,代碼行數:9,代碼來源:ThymeleafConfig.java

示例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;
}
 
開發者ID:mychalvlcek,項目名稱:spring-rest-skeleton,代碼行數:9,代碼來源:EmailConfiguration.java

示例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;
}
 
開發者ID:NovaFox161,項目名稱:DisCal-Discord-Bot,代碼行數:16,代碼來源:ThymeleafTemplateEngine.java

示例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;
}
 
開發者ID:linkedin,項目名稱:custom-gradle-plugin-portal,代碼行數:9,代碼來源:ResourceConfig.java


注:本文中的org.thymeleaf.templatemode.TemplateMode類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。