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


Java ClassLoaderTemplateResolver.setTemplateMode方法代碼示例

本文整理匯總了Java中org.thymeleaf.templateresolver.ClassLoaderTemplateResolver.setTemplateMode方法的典型用法代碼示例。如果您正苦於以下問題:Java ClassLoaderTemplateResolver.setTemplateMode方法的具體用法?Java ClassLoaderTemplateResolver.setTemplateMode怎麽用?Java ClassLoaderTemplateResolver.setTemplateMode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.thymeleaf.templateresolver.ClassLoaderTemplateResolver的用法示例。


在下文中一共展示了ClassLoaderTemplateResolver.setTemplateMode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: configure

import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //導入方法依賴的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

示例2: yadaTemplateResolver

import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //導入方法依賴的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

示例3: templateEngine

import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //導入方法依賴的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

示例4: main

import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //導入方法依賴的package包/類
public static void main(String[] args) {
    ClassLoaderTemplateResolver resolver = new ClassLoaderTemplateResolver();
    resolver.setTemplateMode("XHTML");
    resolver.setSuffix(".html");
    TemplateEngine engine = new TemplateEngine();
    engine.setTemplateResolver(resolver);


    Context context = new Context(Locale.FRANCE);
    context.setVariable("date", new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime()));
    context.setVariable("contact", new Contact("John", "Doe"));

    List<Contact> contacts = new ArrayList<Contact>();
    contacts.add(new Contact("John","Doe"));
    contacts.add(new Contact("Jane","Doe"));
    context.setVariable("contacts",contacts);

    StringWriter writer = new StringWriter();
    engine.process("org/n3r/sandbox/thymeleaf/home", context, writer);

    System.out.println(writer.toString());
}
 
開發者ID:bingoohuang,項目名稱:javacode-demo,代碼行數:23,代碼來源:ThymeleafDemo.java

示例5: generate

import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //導入方法依賴的package包/類
/**
 * Generates the index page.
 *
 * @param _records
 *            the list of records.
 * @throws IOException
 */
public void generate(Map<RecordKey, BenchRecord> _records) throws IOException {
	final TemplateEngine templateEngine = new TemplateEngine();
	final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();

	// XHTML is the default mode, but we set it anyway for better
	// understanding of code
	templateResolver.setTemplateMode("HTML5");
	templateResolver.setCacheable(true);
	templateResolver.setPrefix("templates/");
	templateResolver.setSuffix(".html");
	templateEngine.setTemplateResolver(templateResolver);
	try (final FileWriter fw = new FileWriter(new File(reportFolder, "index.html"))) {
		templateEngine.process("index", new BenchContext(_records), fw);
	}
}
 
開發者ID:sleroy,項目名稱:bench4j,代碼行數:23,代碼來源:HtmlIndexPage.java

示例6: configure

import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //導入方法依賴的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

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

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

示例9: htmlTemplateResolver

import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //導入方法依賴的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

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

示例11: call

import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //導入方法依賴的package包/類
@Override
public JsonResult call() throws Exception {
    JsonResult result = new JsonResult();
    long beginTime = System.currentTimeMillis();
    int index = 1;
    try {
        byte[] dataArray = estateFeignClient.listAllByPage(index);

        ClassLoaderTemplateResolver resolver = new ClassLoaderTemplateResolver();
        resolver.setCacheable(true);
        resolver.setCharacterEncoding(AppConstants.CHARSET_UTF8);
        resolver.setTemplateMode(StandardTemplateModeHandlers.LEGACYHTML5.getTemplateModeName());
        resolver.setPrefix("templates/");//模板所在目錄
        resolver.setSuffix(".html");//模板文件後綴

        while (dataArray != null) {
            List<EstateItemDTO> estateItemList = ProtoStuffUtil.deserializeList(dataArray, EstateItemDTO.class);
            for (EstateItemDTO dto : estateItemList) {
                //構造上下文(Model)
                Context context = new Context(Locale.CHINA, BeanMapUtil.beanToMap(dto));
                GenParam genParam = new GenParam(resolver, context, "estate_detailUI", appProperties.getProducesPath(), dto.getHouseCode());
                // 生成靜態頁麵
                PageGenerator.staticPage(genParam);
            }
            dataArray = estateFeignClient.listAllByPage(++index);
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
        result = new JsonResult(500, e.getMessage());
    }
    long endTime = System.currentTimeMillis();
    LOGGER.info("全量更新執行完畢,累計耗時{}分", (endTime - beginTime) / 1000 / 60);
    return result;
}
 
開發者ID:lupindong,項目名稱:xq_seckill_microservice,代碼行數:35,代碼來源:LianJiaFullCallable.java

示例12: saveInitializeData

import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //導入方法依賴的package包/類
@Override
@Transactional
public void saveInitializeData(byte[] dataArray) throws Exception {
    try {
        EstateItemDTO dto = ProtoStuffUtil.deserialize(dataArray, EstateItemDTO.class);
        EstateItemModel model = new EstateItemModel();

        // 先查看數據庫是否已存在該記錄
        dataArray = estateFeignClient.findItemByHouseCode(dto.getHouseCode());
        if (dataArray != null) {
            model = ProtoStuffUtil.deserialize(dataArray, EstateItemModel.class);
            BeanUtils.copyProperties(dto, model, "id");
            // 先刪除原有圖片
            estateFeignClient.deleteImagesByHouseCode(dto.getHouseCode());
        } else {
            BeanUtils.copyProperties(dto, model);
        }
        // 保存房源條目
        estateFeignClient.saveItem(ProtoStuffUtil.serialize(model));
        // 保存房源圖片
        saveImages(dto);

        ClassLoaderTemplateResolver resolver = new ClassLoaderTemplateResolver();
        resolver.setCacheable(true);
        resolver.setCharacterEncoding(AppConstants.CHARSET_UTF8);
        resolver.setTemplateMode(StandardTemplateModeHandlers.LEGACYHTML5.getTemplateModeName());
        resolver.setPrefix("templates/");//模板所在目錄
        resolver.setSuffix(".html");//模板文件後綴
        //構造上下文(Model)

        Context context = new Context(Locale.CHINA, BeanMapUtil.beanToMap(dto));
        GenParam genParam = new GenParam(resolver, context, "estate_detailUI", appProperties.getProducesPath(), dto.getHouseCode());
        // 生成靜態頁麵
        PageGenerator.staticPage(genParam);
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    }

}
 
開發者ID:lupindong,項目名稱:xq_seckill_microservice,代碼行數:40,代碼來源:CrawlerServiceImpl.java

示例13: emailTemplateResolver

import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //導入方法依賴的package包/類
public ClassLoaderTemplateResolver emailTemplateResolver() {
		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.EMAIL_TEMPLATES_PREFIX); // Attenzione allo slash finale!
//		resolver.setPrefix(YadaConstants.EMAIL_TEMPLATES_PREFIX + "/"); // Attenzione allo slash finale!
		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(40); // Order not needed because resolver on different SpringTemplateEngine
		return resolver;
	}
 
開發者ID:xtianus,項目名稱:yadaframework,代碼行數:16,代碼來源:YadaAppConfig.java

示例14: renderReport

import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //導入方法依賴的package包/類
String renderReport(String template, List<ScreenshotComparisonResult> screenshotComparisonResults) throws FileNotFoundException {

        ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
        templateResolver.setTemplateMode("HTML");
        templateResolver.setPrefix("templates/");
        templateResolver.setSuffix(".html");
        TemplateEngine templateEngine = new TemplateEngine();
        templateEngine.setTemplateResolver(templateResolver);

        final Map<String, Object> variables = prepareVariablesForReportTemplate(screenshotComparisonResults);

        return templateEngine.process(template, new Context(Locale.US, variables));
    }
 
開發者ID:otto-de,項目名稱:jlineup,代碼行數:14,代碼來源:HTMLReportWriter.java

示例15: beforeClass

import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //導入方法依賴的package包/類
@BeforeClass
public static void beforeClass() {
	//Set up shiro
	Ini ini = new Ini();
	Ini.Section usersSection = ini.addSection("users");
	usersSection.put(USER1, PASS1 + ",rolea,roled");
	usersSection.put(USER2, PASS2 + ",roleb,rolec");
	usersSection.put(USER3, PASS3 + ",rolec,rolee");
	Ini.Section rolesSection = ini.addSection("roles");
	rolesSection.put("rolea", "*");
	rolesSection.put("roleb", "permtype1:permaction1:perminst1");
	rolesSection.put("rolec", "permtype1:permaction2:*");
	rolesSection.put("roled", "permtype3:*");
	Factory<SecurityManager> factory = new TestIniSecurityManagerFactory(ini);
	SecurityManager secMgr = factory.getInstance();
	setSecurityManager(secMgr);

	//Set up thymeleaf
	ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
	templateResolver.setCacheable(false);
	templateResolver.setCharacterEncoding("UTF-8");
	templateResolver.setTemplateMode("HTML5");

	templateEngine = new TemplateEngine();
	templateEngine.setTemplateResolver(templateResolver);
	templateEngine.addDialect("shiro", new ShiroDialect());
}
 
開發者ID:usydapeng,項目名稱:thymeleaf3-shiro,代碼行數:28,代碼來源:ShiroDialectTest.java


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