Grails域类,字符串字段TEXT和LONGTEXT [英] Grails domain class, String field TEXT and LONGTEXT

查看:144
本文介绍了Grails域类,字符串字段TEXT和LONGTEXT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Grails领域类中,如何为String字段设置约束,使其MySQL列类型为TEXT或LONGTEXT?



到目前为止我最好的方法是设置约束的大小:

pre $ myTextField(size:0..65535)

导致TEXT

  myTextField(size :0..2147483646)

结果为LONGTEXT(2147483646 = 2 ^ 32/2 - 1 - 1 )



是否有更简洁的方式来指定尺寸?基本上我需要TEXT或LONGTEXT的全部范围,而不必硬编码一堆尺寸值。

您可以声明您的Domain类的映射关闭:

 静态映射= {
myTextField类型:'text'
}

(见 ORM DSL文档


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)

which results in TEXT

myTextField(size:0..2147483646)

results in LONGTEXT (2147483646 = 2^32 / 2 - 1 - 1)

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.

解决方案

You can declare that in the mapping closure of your Domain class:

static mapping = {
   myTextField type: 'text'
}

(See ORM DSL Documentation)

这篇关于Grails域类,字符串字段TEXT和LONGTEXT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆