Grails域类中的字符串列表 [英] List of Strings in a Grails domain class

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

问题描述

我试图在Grails域类的MySql中使用 String List 。 p>

我试过以下内容:

  class Catalog {

List books
String book
static hasMany = [books:book]

}

  class Catalog {

List books






  class Catalog {

String [] books

}
pre>

  class Catalog {

ArrayList< String> books = new ArrayList< String>()

}

编译但该条目不存在于MySQL中。
在MySQL中没有表或列来表示这些数据,我试图用数据填充数组。仍然没有。



有什么想法?

解决方案

通过使用 hasMany 。此外,您需要将 books 定义为 List ,因为没有它,您会得到一个简单的 Set



  class Catalog {
static hasMany = [books :String]
List books
}


I am trying to have a List of String that works in MySql in a Grails domain class.

I have tried the following:

class Catalogue {

List books
String book
static hasMany = [books: book]

}

and

class Catalogue {

List books

}

and

class Catalogue {

String[] books

}

and

class Catalogue {

ArrayList<String> books = new ArrayList<String>()

}

The last three compiles but the entry is not present in MySQL. There is no table, or column to represent this data in MySQL and I have tried populating the array with data. Still nothing.

Any ideas?

解决方案

You can achieve this by using hasMany. Furthermore you need to define books as a List since without it you would get a simple Set that does not allow any duplicates.

class Catalogue {
    static hasMany = [books: String]
    List books
}

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

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