目前,我正在使用grails
和MySQL
。我这样创建用户的域类:
class User {
String userName
String password
String fullName
String toString(){
"${fullName}"
}
static constraints = {
fullName();
userName(unique:true);
password(password:true);
}
}
在运行应用程序时,grails将创建具有结构的表用户
id bigint(20)
version bigint(20)
full_name varchar(255)
password varchar(255)
user_name varchar(255)
但是我想像这样创建自己的表结构
user_id int(20)
full_name varchar(255)
password varchar(255)
user_name varchar(255)
而且我还想知道 Controller 和模型的结构,这样我才能动态传递插入查询。
谁能帮我演示一下或举个例子吗?
最佳答案
要创建自己的表,可以使用映射。Example
class User {
String fname
String postCode
static mapping = {
table 'userTable' //your custom table name if you want
version false //turnoff grails version
id column:'UserId'
firstName column: 'First_Name' //first name column will be like this
postCode type: 'text' //default Grails varchar() but can make to text
//or for id you can use composit key of your chioce for id or even a generator
id composite: ['firstName', 'lastName']
}
}
有关您正在使用的功能的更多信息,请参见此链接[ORM in GRAILS]干杯!!
关于grails - Grails,MySQL,传递查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22088485/