简体   繁体   中英

Fetch label of property in Grails domain

How do I fetch the label property of a domain from messages.properties. For example, I have a domain as following

class Books{
    String name
    String author
    String description
    String rating
}

And in message.properties I have the following

Books.name.label=Title
Books.author.label=Author
Books.description.label=Description
Books.rating.label=Rating

So can I do something like

def fieldName = Books.name.label

and get 'Title' ? Is there any way to do this ?

If you're in a Controller or Service, you can inject the bean

 def messageSource

and then you can call:

 messageSource.getMessage(code, args, defaultMsg, locale)

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