Grails脚手架 - 为域类的这个属性定义可能的值 [英] Grails Scaffolding - define possible values for this property of a domain class
问题描述
我是Grails的新手。我有一个Person域的类为:
class Person {
字符串名字
字符串姓名
字符串性别
日期dateOfBirth
}
想知道我是否可以定义可能值为一个属性 - 说性别为{M,F,U},以便这三个值将在组合框中列出,当使用动态脚手架人控制器。
我只是想知道在Grails框架中是否有这样的功能?如果这样的功能存在,那么我该如何使用它? 解析方案
从文档 http://grails.org/doc/latest/guide/scaffolding.html ,您应该可以使用inList约束:
class Person {
字符串名字
字符串姓名
字符串性别
日期dateOfBirth
def constraints = {
gender(inList:[M,F,U])
}
}
根据您使用的Grails的版本,这应该支持性别字段的选择列表。 2.0+肯定会这样做。
I am new to Grails. I have a Person domain class as :
class Person {
String firstName
String lastName
String gender
Date dateOfBirth
}
And wondering if I can define possible values for a property - say gender as {M, F, U} so that these three values will be listed in combo box when using dynamic scaffolding for Person controller.
Here I just wanted to know if there is such feature in Grails framework? If such feature exists , then how can I use it?
From the documentation http://grails.org/doc/latest/guide/scaffolding.html, you should be able to use an inList constraint:
class Person {
String firstName
String lastName
String gender
Date dateOfBirth
def constraints = {
gender( inList: ["M", "F", "U"])
}
}
This should scaffold to a select list for the gender field, depending on the version of Grails you're using. 2.0+ definitely does this.
这篇关于Grails脚手架 - 为域类的这个属性定义可能的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!