Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
222 views
in Technique[技术] by (71.8m points)

Grails domain class, String field TEXT and 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)

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.

question from:https://stackoverflow.com/questions/433621/grails-domain-class-string-field-text-and-longtext

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

static mapping = {
   myTextField type: 'text'
}

(See ORM DSL Documentation)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...