我必须从Spring引导和Spring数据项目中的数据库中获取velocity模板。我还没有尝试过任何代码,因为我对所有技术(Velocity,Spring启动和数据)都是新手而不是在google上找到任何东西。有没有人试图从db获取模板,请给我建议一些链接或其他我可以参考的内容?在Springboot中从数据库获取velocity模板
更新:我在分贝绑定类(Grails中),我有从Java访问过程。在方法DB类是, 类bindingSubject {
DEF登录
DEF过程= {酒馆,listForMail - >
def mapBinding = [:]
def fund
def perimeters = pub.sub.entities
perimeters.each(){ entity ->
if (fu == null){
if (entity instanceof S)
fu = entity.fu
if (entity instanceof Fund)
fu = fu
}
}mapBinding.entity = fu.name return mapBinding
}
} 和Java代码写入到
- >加载脚本
mapScriptClass = new HashMap();
if (script != null) {
if (mapScriptClass.get(name) == null) {
GroovyCodeSource groovySource = new GroovyCodeSource(script,name,"");
GroovyClassLoader classLoader = new GroovyClassLoader(this.getClass().getClassLoader());
// Load string as Groovy script class.
Class scriptClass = classLoader.parseClass(groovySource);
try {
Object classInstance = scriptClass.newInstance();
ApplicationContext ctx = (ApplicationContext)ServletContextHolder
.getServletContext().getAttribute(ApplicationAttributes.APPLICATION_CONTEXT);
ctx.getAutowireCapableBeanFactory().autowireBeanProperties(classInstance, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
mapScriptClass.put(name, classInstance);
return classInstance;
拨叫分贝过程方法(在Grails的工作原理,如何做到这一点在Java中?)
Object scriptClass = loadScriptService.getScriptClass("scriptBindingSubject"+templateMail.getId(),
templateMail.getScriptBindingSubject());
if (scriptClass != null) {
try{
bindingSubject = scriptClass.process(pub,subMail);
}
现在我不知道如何调用过程方法从Java(至DB)绑定属性
谢谢。
2016-09-21
Khushi
+0
有示例示例https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-web-velocity –
+0
为什么你想存储我们的数据库中的模板?我会更简单,如果他们直接捆绑在您的应用程序 –
+0
嗨,安迪,其实它的一个Grails项目,其中模板以html格式保存在分贝,现在我必须访问一些模板在Java应用程序,在Grails SimpleTemplateEngine正在与GroovyClassLoader一起使用来绑定变量,所以在java中我必须使用类似的东西,除了速度可以与GroovyClassLoader平滑对话之外,还有其他替代品吗? –