本文整理匯總了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));
}
示例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();
}
}
示例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;
}
}
示例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;
}
示例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;
}
示例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());
}
示例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"));
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}