我收到以下错误,当我尝试保存域类,Grails中:Grails领域类保存
法无签名:java.lang.String.save()的参数类型是适用的:()值:[] 可能的解决方案:size(),size(),take(int),wait(),any(),wait(long)。 Stacktrace如下:
我有一个将XML字符串映射到域对象的服务。然后我尝试保存域名并获取该错误。我已经调试过并知道所有的数据都是有效的。这里是我的代码:
def newProfile="";
newProfile = new LinkedinProfile(
firstName : "${linkedinProfileFeed.'first-name'}",
lastName : "${linkedinProfileFeed.'last-name'}",
dobYear : "${linkedinProfileFeed.'date-of-birth'.'year'}",
dobMonth : "${linkedinProfileFeed.'date-of-birth'.'month'}",
dobDay : "${linkedinProfileFeed.'date-of-birth'.'day'}" ,
imgUrl : "${linkedinProfileFeed.'picture-url'}",
siteStandardAddress : "${linkedinProfileFeed.'site-standard-profile-request'}",
oAuthToken : accessTokenKey.toString(),
secretKey : accessTokenSecret.toString()
)
.id="${linkedinProfileFeed.id}".toString()
log.debug("${linkedinProfileFeed.id}".toString())
log.debug("${linkedinProfileFeed.'first-name'}")
log.debug("${linkedinProfileFeed.'last-name'}")
log.debug("${linkedinProfileFeed.'date-of-birth'.'year'}")
log.debug("${linkedinProfileFeed.'date-of-birth'.'month'}")
log.debug("${linkedinProfileFeed.'date-of-birth'.'day'}")
log.debug("${linkedinProfileFeed.'picture-url'}")
log.debug("${linkedinProfileFeed.'site-standard-profile-request'}")
log.debug(accessTokenKey.toString())
log.debug(accessTokenSecret.toString())
log.debug("end debug")
newProfile.save();
而且,我不熟悉Grails和SpringSource的,但在.NET中,我可以访问使用点运算符的对象的属性。例如,如果我有一个如上所述的对象,我可以只输入newProfile。并可以访问所有的属性。在grails中这没有发生。这是由设计或我的代码中的错误?
下面是我的域类。
class LinkedinProfile {
String firstName
String lastName
String dobYear
String dobMonth
String dobDay
String oAuthToken
String secretKey
String id
String imgUrl
String siteStandardAddress
Date dateCreated
Date lastUpdated
long version
static hasMany = [
linkedinLocation : LinkedinLocation,
linkedinSkill : LinkedinSkill
]
static mapping = {
cache true
id generator: 'assigned'
columns {
firstName type:'text'
lastName type:'text'
oAuthToken type:'text'
secretKey type:'text'
dobYear type:'text'
dobMonth type:'text'
dobDay type:'text'
imgUrl type:'text'
siteStandardAddress type:'text'
}
}
static constraints = {
firstName (nullable:true)
lastName (nullable:true)
oAuthToken (nullable:false)
secretKey (nullable:false)
dobYear (nullable:true)
dobMonth (nullable:true)
dobDay (nullable:true)
id (nullable:false)
imgUrl (nullable:true)
siteStandardAddress (nullable:true)
}
def beforeInsert = {
//to do: before insert, capture current email that is stored in the db
}
def afterInsert={
//resave email
}
}
谢谢,就是这么做的。因为我用字符串结束了它,所以我无法访问对象属性。 – jason