【发布时间】:2021-07-10 16:07:22
【问题描述】:
我的域类 User 具有属性“nombre”和“apellido”;
class Usuario {
String nombre
String apellido
static constraints = { nombre size: 5..15, blank: false
apellido size: 5..15, blank: false
}
static mapping = {
table 'usuario'
version false
nombre column: 'First_Name'
apellido column: 'First_Name'
addresses lazy: false
}
// static mapping = {
// table 'Usuario'
// }*/
在控制器内部,我创建了两个对象并将它们保存到链接数据库中
class UsuarioController {
def index() {
def b = new Usuario(nombre: "matyui", apellido: "Rimollo")
System.out.println(b.nombre)
b.save(flush: true)
def c = new Usuario(nombre: "marcio",apellido: "Razzor")
c.save(flush: true)
}
这为我创建了一个新表“usuario”,但它没有这两个属性(“nombre”和“apellido”),而只有一个属性“id”类型 bigint 和属性 userpkey; 我怎样才能让它在数据源表中创建我的域类的属性? (我也尝试创建一个表并尝试插入它们,但没有成功(此操作在域类“usuario”的代码中注释))。请参阅下一个链接中的图片。
https://i.stack.imgur.com/NOp8U.png
我的 grails 版本是 3.3.X y 我的数据源是 postgreSQL; 非常感谢
【问题讨论】:
-
在您的映射块中 apellido 不应该是姓氏或姓氏而不是名字吗?
-
是的,但结果没有什么不同!!!即使我删除了映射并且域类仍然是这样的:String nombre;字符串 apellido;静态约束 = { nombre 大小:5..15,空白:假 apellido 大小:5..15,空白:假; } 得到相同的结果。谢谢
标签: grails