本文整理匯總了Java中org.thymeleaf.TemplateEngine.setTemplateResolver方法的典型用法代碼示例。如果您正苦於以下問題:Java TemplateEngine.setTemplateResolver方法的具體用法?Java TemplateEngine.setTemplateResolver怎麽用?Java TemplateEngine.setTemplateResolver使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.thymeleaf.TemplateEngine
的用法示例。
在下文中一共展示了TemplateEngine.setTemplateResolver方法的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);
}
示例2: 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();
}
}
示例3: 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);
}
示例4: 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());
}
示例5: 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;
}
示例6: 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);
}
示例7: 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);
}
}
示例8: 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);
}
}
示例9: init
import org.thymeleaf.TemplateEngine; //導入方法依賴的package包/類
/**
* Initialize the Thymeleaf template engine.
*/
@Override
public void init() {
ServletConfig config = this.getServletConfig();
ServletContextTemplateResolver templateresolver = new ServletContextTemplateResolver();
templateresolver.setPrefix(config.getInitParameter(INIT_PARAM_PREFIX));
templateresolver.setSuffix(config.getInitParameter(INIT_PARAM_SUFFIX));
templateresolver.setTemplateMode(config.getInitParameter(INIT_PARAM_TEMPLATEMODE));
templateresolver.setCacheable(false);
templateresolver.setCharacterEncoding(CHARACTER_ENCODING);
templateengine = new TemplateEngine();
templateengine.setTemplateResolver(templateresolver);
Set<IDialect> dialects = new HashSet<IDialect>();
dialects.add(new SpringStandardDialect());
dialects.add(new SqlDialect());
templateengine.setDialects(dialects);
templateengine.initialize();
}
示例10: getEngine
import org.thymeleaf.TemplateEngine; //導入方法依賴的package包/類
protected TemplateEngine getEngine() {
// create engine
if (templateEngine == null) {
// use solr core here
templateResolver.setPrefix(configuration.get("tl.prefix", "templates/"));
TemplateEngine te = new TemplateEngine();
te.setTemplateResolver(templateResolver);
te.addDialect(layoutDialect);
// check race condition, avoid synchronized block
if (templateEngine == null) {
templateEngine = te;
}
}
return templateEngine;
}
示例11: configure
import org.thymeleaf.TemplateEngine; //導入方法依賴的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));
}
示例12: initializeTemplateEngine
import org.thymeleaf.TemplateEngine; //導入方法依賴的package包/類
private void initializeTemplateEngine(String mode) {
if (mode.equals(templateMode)) {
return;
}
templateMode = mode;
templateResolver = new FileTemplateResolver();
templateResolver.setPrefix(templatesPath.getAbsolutePath() + File.separatorChar);
templateResolver.setCharacterEncoding(config.getString(Keys.TEMPLATE_ENCODING));
templateResolver.setTemplateMode(mode);
templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
}
示例13: testThymeleafTemplate
import org.thymeleaf.TemplateEngine; //導入方法依賴的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);
}
示例14: testApp
import org.thymeleaf.TemplateEngine; //導入方法依賴的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);
}
示例15: renderTemplate
import org.thymeleaf.TemplateEngine; //導入方法依賴的package包/類
@Override
public String renderTemplate() {
TemplateEngine templateEngine = new TemplateEngine();
AbstractConfigurableTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setTemplateMode(this.templateMode);
templateEngine.setTemplateResolver(templateResolver);
return templateEngine.process(template, new Context(Locale.SIMPLIFIED_CHINESE, context));
}