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


Java TemplateEngine類代碼示例

本文整理匯總了Java中org.thymeleaf.TemplateEngine的典型用法代碼示例。如果您正苦於以下問題:Java TemplateEngine類的具體用法?Java TemplateEngine怎麽用?Java TemplateEngine使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: AssetsBundleCustomErrorHandler

import org.thymeleaf.TemplateEngine; //導入依賴的package包/類
public AssetsBundleCustomErrorHandler(Environment environment) {
    this.environment = environment;

    TemplateResolver templateResolver = new TemplateResolver();
    String baseDirForTemplates = System.getProperty("baseDirForTemplates");
    if (baseDirForTemplates != null) {
        templateResolver.setResourceResolver(new FileResourceResolver());
        templateResolver.setPrefix(baseDirForTemplates + "/templates/");
    } else {
        templateResolver.setResourceResolver(new ThymeleafResourceResolver());
        templateResolver.setPrefix("/templates/");
    }
    templateResolver.setTemplateMode("HTML5");
    templateResolver.setCacheable(false);
    templateResolver.setCharacterEncoding(StandardCharsets.UTF_8.name());
    engine = new TemplateEngine();
    engine.setTemplateResolver(templateResolver);
}
 
開發者ID:openregister,項目名稱:openregister-java,代碼行數:19,代碼來源:AssetsBundleCustomErrorHandler.java

示例2: renderNonWebAppTemplate

import org.thymeleaf.TemplateEngine; //導入依賴的package包/類
@Test
public void renderNonWebAppTemplate() throws Exception {
	AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
			ThymeleafAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	assertThat(context.getBeanNamesForType(ViewResolver.class).length).isEqualTo(0);
	try {
		TemplateEngine engine = context.getBean(TemplateEngine.class);
		Context attrs = new Context(Locale.UK,
				Collections.singletonMap("greeting", "Hello World"));
		String result = engine.process("message", attrs);
		assertThat(result).contains("Hello World");
	}
	finally {
		context.close();
	}
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:18,代碼來源:ThymeleafAutoConfigurationTests.java

示例3: buildIndex

import org.thymeleaf.TemplateEngine; //導入依賴的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

示例4: staticPage

import org.thymeleaf.TemplateEngine; //導入依賴的package包/類
public static void staticPage(GenParam genParam) throws Exception {

        // 構造模板引擎
        TemplateEngine templateEngine = new TemplateEngine();
        templateEngine.setTemplateResolver(genParam.getResolver());

        // 渲染模板
        Assert.notNull(genParam.getTemplateName(), "templateName must not be null!");
        String filePath = genParam.getOutputPath() + genParam.getTemplateName().split("_")[0] + "/";
        //LOGGER.warn("output file path: {}", filePath);
        File file = new File(filePath);
        if (!file.exists()) file.mkdirs();
        Assert.notNull(genParam.getHouseCode(), "HouseCode must not be null!");
        // 輸出文件
        FileWriter write = new FileWriter(filePath + genParam.getHouseCode() + ".shtml");
        templateEngine.process(genParam.getTemplateName(), genParam.getContext(), write);
    }
 
開發者ID:lupindong,項目名稱:xq_seckill_microservice,代碼行數:18,代碼來源:PageGenerator.java

示例5: main

import org.thymeleaf.TemplateEngine; //導入依賴的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

示例6: createFromConfigClass

import org.thymeleaf.TemplateEngine; //導入依賴的package包/類
@Test
public void createFromConfigClass() throws Exception {
	EnvironmentTestUtils.addEnvironment(this.context, "spring.thymeleaf.mode:XHTML",
			"spring.thymeleaf.suffix:");
	this.context.register(ThymeleafAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	this.context.refresh();
	TemplateEngine engine = this.context.getBean(TemplateEngine.class);
	Context attrs = new Context(Locale.UK, Collections.singletonMap("foo", "bar"));
	String result = engine.process("template.txt", attrs);
	assertThat(result).isEqualTo("<html>bar</html>");
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:13,代碼來源:ThymeleafAutoConfigurationTests.java

示例7: overrideCharacterEncoding

import org.thymeleaf.TemplateEngine; //導入依賴的package包/類
@Test
public void overrideCharacterEncoding() throws Exception {
	EnvironmentTestUtils.addEnvironment(this.context,
			"spring.thymeleaf.encoding:UTF-16");
	this.context.register(ThymeleafAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	this.context.refresh();
	this.context.getBean(TemplateEngine.class).initialize();
	ITemplateResolver resolver = this.context.getBean(ITemplateResolver.class);
	assertThat(resolver instanceof TemplateResolver).isTrue();
	assertThat(((TemplateResolver) resolver).getCharacterEncoding())
			.isEqualTo("UTF-16");
	ThymeleafViewResolver views = this.context.getBean(ThymeleafViewResolver.class);
	assertThat(views.getCharacterEncoding()).isEqualTo("UTF-16");
	assertThat(views.getContentType()).isEqualTo("text/html;charset=UTF-16");
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:17,代碼來源:ThymeleafAutoConfigurationTests.java

示例8: activate

import org.thymeleaf.TemplateEngine; //導入依賴的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

示例9: CaptchaService

import org.thymeleaf.TemplateEngine; //導入依賴的package包/類
@Autowired
public CaptchaService(UserInfoValidator userInfoValidator, LsPushProperties lsPushProperties,
    JavaMailSender mailSender, TemplateEngine templateEngine, ObjectMapper objectMapper,
    UserRepository userRepo) {
    mUserInfoValidator = userInfoValidator;
    serverName = lsPushProperties.getServerName();
    serverUrl = lsPushProperties.getServerUrl();
    serverEmail = lsPushProperties.getServerEmail();
    mMailSender = mailSender;
    mTemplateEngine = templateEngine;
    mObjectMapper = objectMapper;
    mUserRepo = userRepo;
    mAuthCodeMap = CacheBuilder.newBuilder()
        .initialCapacity(100)
        .maximumSize(500)
        .expireAfterWrite(30, TimeUnit.MINUTES)
        .build();

    mStringFunnel = (Funnel<String>) (from, into) -> into.putString(from, StandardCharsets.UTF_8);
    resetBloomFilter();
}
 
開發者ID:TomeOkin,項目名稱:LsPush-Server,代碼行數:22,代碼來源:CaptchaService.java

示例10: getTemplateEngine

import org.thymeleaf.TemplateEngine; //導入依賴的package包/類
/**
 * Producer method building and configuring the {@link TemplateEngine} instance to be used in the application. The
 * engine's template resolver is set up to follow MVC requirements. JAX-RS parameter conversion bridges are
 * detected, and if one is present, the engine is set up to use it.
 *
 * Subclasses can override and {@link javax.enterprise.inject.Specializes specialize} this method to add additional
 * configuration (e.g. call {@link TemplateEngine#addDialect(org.thymeleaf.dialect.IDialect)} to add a dialect).
 *
 * @return the newly created and configured {@link TemplateEngine} instance
 */
@Produces public TemplateEngine getTemplateEngine() {
    final TemplateEngine engine = new TemplateEngine();
    final ITemplateResolver tr = new MVCTemplateResolver(servletContext, mvcContext);
    engine.setTemplateResolver(tr);
    try {
        final Class<?> pcbClass = Class.forName("hu.inbuss.thymeleaf.jaxrs.ParamConverterBridge");
        final Bean<?> pcbBean = beanManager.resolve(beanManager.getBeans(pcbClass));
        final CreationalContext pcbContext = beanManager.createCreationalContext(pcbBean);
        final ParamConverterBridge pcb = (ParamConverterBridge) beanManager.getReference(pcbBean, pcbClass, pcbContext);
        pcb.installInto(engine);
    } catch (final ClassNotFoundException cnfe) {
        // the Jersey integration module is not present, do nothing
    }
    return engine;
}
 
開發者ID:inbuss,項目名稱:thymeleaf-mvc,代碼行數:26,代碼來源:TemplateEngineProducer.java

示例11: renderNonWebAppTemplate

import org.thymeleaf.TemplateEngine; //導入依賴的package包/類
@Test
public void renderNonWebAppTemplate() throws Exception {
	AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
			ThymeleafAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	assertEquals(0, context.getBeanNamesForType(ViewResolver.class).length);
	try {
		TemplateEngine engine = context.getBean(TemplateEngine.class);
		Context attrs = new Context(Locale.UK,
				Collections.singletonMap("greeting", "Hello World"));
		String result = engine.process("message", attrs);
		assertThat(result, containsString("Hello World"));
	}
	finally {
		context.close();
	}
}
 
開發者ID:Nephilim84,項目名稱:contestparser,代碼行數:18,代碼來源:ThymeleafAutoConfigurationTests.java

示例12: init

import org.thymeleaf.TemplateEngine; //導入依賴的package包/類
@Override
public void init() {
  // Setup ThymeLeaf
  ServletContextTemplateResolver templateResolver =
      new ServletContextTemplateResolver(this.getServletContext());

  templateResolver.setPrefix("/WEB-INF/templates/");
  templateResolver.setSuffix(".html");
  templateResolver.setCacheTTLMs(Long.valueOf(1200000L)); // TTL=20m

  // Cache is set to true by default. Set to false if you want templates to
  // be automatically updated when modified.
  templateResolver.setCacheable(true);

  templateEngine = new TemplateEngine();
  templateEngine.setTemplateResolver(templateResolver);
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:18,代碼來源:GaeInfoServlet.java

示例13: generateWithThymeleaf

import org.thymeleaf.TemplateEngine; //導入依賴的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

示例14: generate

import org.thymeleaf.TemplateEngine; //導入依賴的package包/類
/**
 * Generates site report using thymeleaf template engine.
 *
 * @param diffReport
 *        container with parsed data.
 * @param diffConfiguration
 *        merged configurations from both reports.
 * @param paths
 *        CLI paths.
 * @throws IOException
 *         on failure to write site to disc.
 */
public static void generate(DiffReport diffReport, MergedConfigurationModule diffConfiguration,
        CliPaths paths) throws IOException {
    // setup thymeleaf engine
    final TemplateEngine tplEngine = getTemplateEngine();
    // setup xreference generator
    final XrefGenerator xrefGenerator = new XrefGenerator(paths.getRefFilesPath(),
            paths.getOutputPath().resolve(Main.XREF_FILEPATH), paths.getOutputPath());
    // html generation
    final Path sitepath = paths.getOutputPath().resolve(SITEPATH);
    final FileWriter writer = new FileWriter(sitepath.toString());
    try {
        // write statistics
        generateHeader(tplEngine, writer, diffReport.getStatistics(), diffConfiguration);
        // write parsed content
        generateBody(tplEngine, writer, diffReport, paths, xrefGenerator);
        // write html footer
        tplEngine.process("footer", new Context(), writer);
    }
    finally {
        writer.close();
    }
}
 
開發者ID:checkstyle,項目名稱:contribution,代碼行數:35,代碼來源:SiteGenerator.java

示例15: generate

import org.thymeleaf.TemplateEngine; //導入依賴的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


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