简体   繁体   中英

Use StringTemplate with Grails domain class as model

Can I use Grails Domain Classes as Model for ST (StringTemplate) library.

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 ". Should that work or do I need to write an adapter to use Grails Domain classes as Model for ST?

Without seeing your Person domainClass, I ques you meant {personInstance.firstName} instead of {personInstance.first_name}. ST supports accessing properties.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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