本文整理匯總了Java中org.thymeleaf.templateresolver.ClassLoaderTemplateResolver.setCacheable方法的典型用法代碼示例。如果您正苦於以下問題:Java ClassLoaderTemplateResolver.setCacheable方法的具體用法?Java ClassLoaderTemplateResolver.setCacheable怎麽用?Java ClassLoaderTemplateResolver.setCacheable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.thymeleaf.templateresolver.ClassLoaderTemplateResolver
的用法示例。
在下文中一共展示了ClassLoaderTemplateResolver.setCacheable方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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);
}
}
示例4: 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));
}
示例5: 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);
}
示例6: 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);
}
示例7: 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;
}
示例8: 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;
}
示例9: 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);
}
}
示例10: 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;
}
示例11: beforeClass
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //導入方法依賴的package包/類
@BeforeClass
public static void beforeClass() {
//Set up shiro
Ini ini = new Ini();
Ini.Section usersSection = ini.addSection("users");
usersSection.put(USER1, PASS1 + ",rolea,roled");
usersSection.put(USER2, PASS2 + ",roleb,rolec");
usersSection.put(USER3, PASS3 + ",rolec,rolee");
Ini.Section rolesSection = ini.addSection("roles");
rolesSection.put("rolea", "*");
rolesSection.put("roleb", "permtype1:permaction1:perminst1");
rolesSection.put("rolec", "permtype1:permaction2:*");
rolesSection.put("roled", "permtype3:*");
Factory<SecurityManager> factory = new TestIniSecurityManagerFactory(ini);
SecurityManager secMgr = factory.getInstance();
setSecurityManager(secMgr);
//Set up thymeleaf
ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setCacheable(false);
templateResolver.setCharacterEncoding("UTF-8");
templateResolver.setTemplateMode("HTML5");
templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
templateEngine.addDialect("shiro", new ShiroDialect());
}
示例12: textTemplateResolver
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //導入方法依賴的package包/類
private ITemplateResolver textTemplateResolver() {
final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setOrder(1);
templateResolver.setResolvablePatterns(Collections.singleton("text/*"));
templateResolver.setPrefix("/mail/");
templateResolver.setSuffix(".txt");
templateResolver.setTemplateMode(TemplateMode.TEXT);
templateResolver.setCharacterEncoding("UTF-8");
templateResolver.setCacheable(false);
return templateResolver;
}
示例13: htmlTemplateResolver
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //導入方法依賴的package包/類
private ITemplateResolver htmlTemplateResolver() {
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);
return templateResolver;
}
示例14: stringTemplateResolver
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //導入方法依賴的package包/類
private ITemplateResolver stringTemplateResolver() {
final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setOrder(3);
templateResolver.setTemplateMode(TemplateMode.HTML5);
templateResolver.setCacheable(false);
return templateResolver;
}
示例15: init
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; //導入方法依賴的package包/類
@PostConstruct
public void init() {
String charset = StandardCharsets.UTF_8.name();
contentType = MediaType.TEXT_HTML_TYPE.withCharset(charset);
ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setPrefix("templates/");
templateResolver.setSuffix(".html");
templateResolver.setCacheable(false);
templateResolver.setCharacterEncoding(charset);
templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
}