Grails 域类,字符串字段 TEXT 和 LONGTEXT [英] Grails domain class, String field TEXT and LONGTEXT
本文介绍了Grails 域类,字符串字段 TEXT 和 LONGTEXT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Grails 域类中,如何设置 String 字段的约束,使其 MySQL 列类型为 TEXT 或 LONGTEXT?
In a Grails domain class, how do I set the constraint for a String field so that its MySQL column type is TEXT or LONGTEXT?
到目前为止,我最好的方法是设置约束的大小:
So far my best approach is to set the constraint's size:
myTextField(size:0..65535)
导致文本
myTextField(size:0..2147483646)
结果为 LONGTEXT (2147483646 = 2^32/2 - 1 - 1)
results in LONGTEXT (2147483646 = 2^32 / 2 - 1 - 1)
有没有更简洁的方法来指定尺寸?基本上我想要完整范围的 TEXT 或 LONGTEXT 而不必硬编码一堆大小值.
Is there a cleaner way to specify the size? Basically I want the full range of TEXT or LONGTEXT without having to hardcode a bunch of size values.
推荐答案
你可以在你的 Domain 类的映射闭包中声明:
You can declare that in the mapping closure of your Domain class:
static mapping = {
myTextField type: 'text'
}
(参见 ORM DSL 文档)
这篇关于Grails 域类,字符串字段 TEXT 和 LONGTEXT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文