org.thymeleaf.templateresolver.StringTemplateResolver Java Examples

The following examples show how to use org.thymeleaf.templateresolver.StringTemplateResolver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TemplateUtilsTest.java    From SkaETL with Apache License 2.0 6 votes vote down vote up
@Test
public void astext() {

    StringTemplateResolver templateResolver = new StringTemplateResolver();
    templateResolver.setOrder(1);
    templateResolver.setTemplateMode(TemplateMode.TEXT);
    // TODO Cacheable or Not ?
    templateResolver.setCacheable(false);
    TemplateEngine templateEngine = new TemplateEngine();
    templateEngine.setTemplateResolver(templateResolver);

    Context context = new Context();

    context.setVariable("mavar","cela");
    String process = templateEngine.process("ceci [[${mavar}]]", context);
    assertThat(process).isEqualTo("ceci cela");

    String notInterpreted = templateEngine.process("ceci <span th:text=\"${mavar}\"></span>", context);
    assertThat(notInterpreted).isEqualTo("ceci <span th:text=\"${mavar}\"></span>");
}
 
Example #2
Source File: TemplateUtilsTest.java    From SkaETL with Apache License 2.0 6 votes vote down vote up
@Test
public void ashtml() {

    StringTemplateResolver templateResolver = new StringTemplateResolver();
    templateResolver.setOrder(1);
    templateResolver.setTemplateMode(TemplateMode.HTML);
    // TODO Cacheable or Not ?
    templateResolver.setCacheable(false);
    TemplateEngine templateEngine = new TemplateEngine();
    templateEngine.setTemplateResolver(templateResolver);

    Context context = new Context();

    context.setVariable("mavar","cela");
    String process = templateEngine.process("ceci [[${mavar}]]", context);
    assertThat(process).isEqualTo("ceci cela");

    String variant = templateEngine.process("ceci <span th:text=\"${mavar}\"></span>", context);
    assertThat(variant).isEqualTo("ceci <span>cela</span>");
}
 
Example #3
Source File: ThymeleafTest.java    From ext-opensource-netty with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 使用 Thymeleaf 渲染 HTML
 * @param template  HTML模板
 * @param params 参数
 * @return  渲染后的HTML
 */
public static String render(String template,Map<String,Object> params){
    Context context = new Context();
    context.setVariables(params);
    TemplateEngine engine=new TemplateEngine();
    
    StringTemplateResolver  resolver = new StringTemplateResolver();
    engine.setTemplateResolver(resolver);
    return engine.process(template,context);
}
 
Example #4
Source File: TemplateUtils.java    From SkaETL with Apache License 2.0 5 votes vote down vote up
private TemplateUtils() {
    StringTemplateResolver templateResolver = new StringTemplateResolver();
    templateResolver.setTemplateMode(TemplateMode.HTML);
    // TODO Cacheable or Not ?
    templateResolver.setCacheable(false);
    stringTemplateEngine = new TemplateEngine();
    stringTemplateEngine.addTemplateResolver(templateResolver);
}
 
Example #5
Source File: TemplateConfig.java    From zhcet-web with Apache License 2.0 5 votes vote down vote up
private ITemplateResolver stringTemplateResolver() {
    final StringTemplateResolver templateResolver = new StringTemplateResolver();
    templateResolver.setOrder(4);
    // No resolvable pattern, will simply process as a String template everything not previously matched
    templateResolver.setTemplateMode(TemplateMode.HTML);
    templateResolver.setCacheable(thymeleafProperties.isCache());
    return templateResolver;
}
 
Example #6
Source File: TemplateEngineModule.java    From EDDI with Apache License 2.0 5 votes vote down vote up
private TemplateEngine createTemplateEngine(TemplateMode templateMode) {
    TemplateEngine templateEngine = new TemplateEngine();
    StringTemplateResolver templateResolver = new StringTemplateResolver();
    templateResolver.setTemplateMode(templateMode);
    templateEngine.addTemplateResolver(templateResolver);

    return templateEngine;
}
 
Example #7
Source File: SendMailHelper.java    From spring-boot-doma2-sample with Apache License 2.0 4 votes vote down vote up
protected ITemplateResolver templateResolver() {
    val resolver = new StringTemplateResolver();
    resolver.setTemplateMode("TEXT");
    resolver.setCacheable(false); // 安全をとってキャッシュしない
    return resolver;
}
 
Example #8
Source File: StringResolverAdapter.java    From ogham with Apache License 2.0 4 votes vote down vote up
@Override
public ITemplateResolver adapt(ResourceResolver resolver) {
	StringTemplateResolver templateResolver = new StringTemplateResolver();
	applyOptions(templateResolver);
	return templateResolver;
}