我是groovy grails的新开发人员,并且在数据库测试下有一个名为user的表。我通过使用grails成功登录了该数据库,但无法成功注册新用户。我已经使用GORM导入数据库,但是有一个奇怪的错误,我找不到任何可能的解决方案来解决此问题。
我的域类
package com.example.ulu
import grails.persistence.Entity;
@Entity
class User {
String userName
String password
String fullName
static constraints = {
}
}
Controller
def registeruser = {
User a = new User()
a.fullName("John")
a.userName("burak")
a.password("1")
a.save()
}
插件和依赖项
dependencies {
runtime 'mysql:mysql-connector-java:5.1.29'
test "org.grails:grails-datastore-test-support:1.0.2-grails-2.4"
compile "javax.validation:validation-api:1.1.0.Final"
compile "org.grails:grails-spring:2.4.5"
compile "org.codehaus.groovy:groovy-all:2.4.5"
runtime "org.hibernate:hibernate-validator:5.0.3.Final"
}
plugins {
build ":tomcat:8.0.22"
compile ":scaffolding:2.1.2"
compile ':cache:1.1.8'
compile ":asset-pipeline:2.1.5"
runtime ":resources:1.2.14"
runtime ":hibernate4:4.3.8.1"
runtime ":database-migration:1.4.0"
runtime ":jquery:1.11.1"
}
最佳答案
a.fullName("John")
a.userName("burak")
a.password("1")
都错了Groovy使用JavaBean表示法,并且属性分配必须类似于:
a.fullName = "John"
a.userName = "burak"
a.password ="1"
要么
a.setFullName "John"
a.setUserName "burak"
a.setPassword "1"
要么
a[ 'fullName' ] = "John"
a[ 'userName' ] = "burak"
a[ 'password' ] ="1"
关于database - groovy.lang.MissingMethodException-保存GORM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33105067/