本文整理汇总了Java中org.thymeleaf.templateresolver.ClassLoaderTemplateResolver.setPrefix方法的典型用法代码示例。如果您正苦于以下问题:Java ClassLoaderTemplateResolver.setPrefix方法的具体用法?Java ClassLoaderTemplateResolver.setPrefix怎么用?Java ClassLoaderTemplateResolver.setPrefix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.thymeleaf.templateresolver.ClassLoaderTemplateResolver
的用法示例。
在下文中一共展示了ClassLoaderTemplateResolver.setPrefix方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
}
示例2: 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;
}
示例3: 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;
}
示例4: 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"));
}
示例5: 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);
}
}
示例6: 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));
}
示例7: 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);
}
示例8: 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);
}
示例9: 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;
}
示例10: 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;
}
示例11: 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;
}
示例12: 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);
}
}
示例13: emailTemplateResolver
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //导入方法依赖的package包/类
public ClassLoaderTemplateResolver emailTemplateResolver() {
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.EMAIL_TEMPLATES_PREFIX); // Attenzione allo slash finale!
// resolver.setPrefix(YadaConstants.EMAIL_TEMPLATES_PREFIX + "/"); // Attenzione allo slash finale!
Set<String> patterns = new HashSet<>();
patterns.add("/email/*"); // Start with "email"
resolver.setResolvablePatterns(patterns);
resolver.setSuffix(".html");
resolver.setCharacterEncoding("UTF-8");
resolver.setTemplateMode(TemplateMode.HTML);
resolver.setCacheable(config.isProductionEnvironment());
// resolver.setOrder(40); // Order not needed because resolver on different SpringTemplateEngine
return resolver;
}
示例14: renderReport
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //导入方法依赖的package包/类
String renderReport(String template, List<ScreenshotComparisonResult> screenshotComparisonResults) throws FileNotFoundException {
ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setTemplateMode("HTML");
templateResolver.setPrefix("templates/");
templateResolver.setSuffix(".html");
TemplateEngine templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
final Map<String, Object> variables = prepareVariablesForReportTemplate(screenshotComparisonResults);
return templateEngine.process(template, new Context(Locale.US, variables));
}
示例15: defaultTemplateResolver
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //导入方法依赖的package包/类
private ITemplateResolver defaultTemplateResolver() {
ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setPrefix("/views/");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode("HTML");
return templateResolver;
}
开发者ID:gravitee-io,项目名称:graviteeio-access-management,代码行数:8,代码来源:ThymeleafTemplateResolverFactory.java