简体   繁体   English

将StringTemplate与Grails域类一起使用作为模型

[英]Use StringTemplate with Grails domain class as model

Can I use Grails Domain Classes as Model for ST (StringTemplate) library. 我可以将Grails域类用作ST(StringTemplate)库的模型。

eg 例如

String content = "Hello {personInstance.first_name}!"
char startChar = '{'
char endChar = '}'
ST st = new ST(content, startChar, endChar)
st.add("personInstance", personInstance)
st.render()

What I get back from the render is simply "Hello ". 我从渲染中得到的只是“ Hello”。 Should that work or do I need to write an adapter to use Grails Domain classes as Model for ST? 这应该可行还是我需要编写一个适配器以将Grails域类用作ST的模型?

Without seeing your Person domainClass, I ques you meant {personInstance.firstName} instead of {personInstance.first_name}. 在没有看到您的Person domainClass的情况下,我问您的意思是{personInstance.firstName}而不是{personInstance.first_name}。 ST supports accessing properties. ST支持访问属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM