当前位置: 首页>>代码示例>>Java>>正文


Java ClassLoaderTemplateResolver类代码示例

本文整理汇总了Java中org.thymeleaf.templateresolver.ClassLoaderTemplateResolver的典型用法代码示例。如果您正苦于以下问题:Java ClassLoaderTemplateResolver类的具体用法?Java ClassLoaderTemplateResolver怎么用?Java ClassLoaderTemplateResolver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ClassLoaderTemplateResolver类属于org.thymeleaf.templateresolver包,在下文中一共展示了ClassLoaderTemplateResolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: buildIndex

import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //导入依赖的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();
	}
}
 
开发者ID:mariusj,项目名称:validator-sitemap,代码行数:27,代码来源:SitemapValidator.java

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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"));
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:17,代码来源:ThymeleafTestCase.java

示例8: generateWithThymeleaf

import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //导入依赖的package包/类
/**
 * Generates output file with release notes using Thymeleaf.
 * @param variables the map which represents template variables.
 * @param outputFile output file.
 * @param templateFilename template name.
 * @throws IOException if I/O error occurs.
 */
public static void generateWithThymeleaf(Map<String, Object> variables, String outputFile,
        String templateFilename) throws IOException {

    final TemplateEngine engine = new TemplateEngine();
    final AbstractConfigurableTemplateResolver resolver = new ClassLoaderTemplateResolver();
    resolver.setPrefix(TEMPLATE_FOLDER_PATH);
    engine.setTemplateResolver(resolver);

    final IContext ctx = new Context(Locale.US, variables);

    try (Writer fileWriter = new OutputStreamWriter(
            new FileOutputStream(outputFile), StandardCharsets.UTF_8)) {
        engine.process(templateFilename, ctx, fileWriter);
    }
}
 
开发者ID:checkstyle,项目名称:contribution,代码行数:23,代码来源:TemplateProcessor.java

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: 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

示例15: 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


注:本文中的org.thymeleaf.templateresolver.ClassLoaderTemplateResolver类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。