如何在 Grails (GORM) 上定义整数属性长度?
How to define an integer attribute length on Grails (GORM)?
我想创建一个具有整数属性的域 class,该属性应映射到长度为 2 的数据库,默认情况下 GORM 创建一个 INT(11)。
例如:
class MyDomain {
int options
static constraints = {
options(min: 0, max: 99, maxSize: 2)
// options(size: 2) -> Size are not available for integer attribute.
}
static mapping = {
options(length: 2) // Does't work too
}
}
观察员:我正在使用 Grails v2.5.2。
对于整数属性,您可以在映射中使用 sqlType :
static mapping = {
options sqlType: 'INT(2)'
}
您可以在此处找到有关映射的更多信息:http://grails.github.io/grails-doc/2.5.1/ref/Database%20Mapping/column.html
我想创建一个具有整数属性的域 class,该属性应映射到长度为 2 的数据库,默认情况下 GORM 创建一个 INT(11)。
例如:
class MyDomain {
int options
static constraints = {
options(min: 0, max: 99, maxSize: 2)
// options(size: 2) -> Size are not available for integer attribute.
}
static mapping = {
options(length: 2) // Does't work too
}
}
观察员:我正在使用 Grails v2.5.2。
对于整数属性,您可以在映射中使用 sqlType :
static mapping = {
options sqlType: 'INT(2)'
}
您可以在此处找到有关映射的更多信息:http://grails.github.io/grails-doc/2.5.1/ref/Database%20Mapping/column.html