We're upgrading from Thymeleaf 2.1 to 3.0.5. Our current set up (before upgrading) has many thymeleaf templates defined and stored in a database table.
When we attempt to upgrade to 3.x our 2.1 code no longer works...ok fine but we can't find any good examples on how to do basically the same thing with Thymeleaf 3.0.5. Has anyone implemented this?
Even a decent example of how to implement org.thymeleaf.templateresolver.StringTemplateResolver would probably push us in the right direction...but we can't find anything on that either.
This is what we used in 2.1:
public class ThymeleafTemplateResolver extends TemplateResolver {
private final static String PREFIX = "";
public ThymeleafTemplateResolver() {
setResourceResolver(new DbResourceResolver());
setResolvablePatterns(Sets.newHashSet(PREFIX + "*"));
}
@Override
protected String computeResourceName(TemplateProcessingParameters params) {
String templateName = params.getTemplateName();
return templateName.substring(PREFIX.length());
}
private class DbResourceResolver implements IResourceResolver {
@Override
public InputStream getResourceAsStream(TemplateProcessingParameters params, String template) {
ThymeleafTemplateDao thymeleaftemplateDao = ApplicationContextProvider.getApplicationContext().getBean(ThymeleafTemplateDao.class);
ThymeleafTemplate thymeleafTemplate = thymeleaftemplateDao.findByTemplate(template);
if (thymeleafTemplate != null) {
return new ByteArrayInputStream(thymeleafTemplate.getContent().getBytes());
}
return null;
}
@Override
public String getName() {
return "dbResourceResolver";
}
}
}
Any help is appreciated...
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…