繁体   English   中英

没有为参数指定值-Grails

[英]No value specified for parameter - Grails

在域类上使用查找方式时遇到问题:

我得到的错误是: ERROR util.JDBCExceptionReporter - No value specified for parameter 2

域类是:

class AppDetail {

String name
String url
Boolean active

static hasMany = [authString:AppIdentifier]


static constraints = {
    name(unique:true,blank:false)
    active(nullable:true)
}

class AppIdentifier {

Date added
String authString

static belongsTo = [authString:AppDetail]

static constraints = {

    added()
    authString(blank:false)

}

查找依据是:

def identifier = AppIdentifer.findByAuthString('test')
def appDetails = AppDetail.findByAuthString(identifier) 

谁能提供有关此错误含义的任何见解?

提前致谢!

您有太多名为“ authString”的字段。 这是重做相同类的另一种方法:

class AppDetail {

String name
String url
Boolean active

static hasMany = [identifiers:AppIdentifier]


static constraints = {
    name(unique:true,blank:false)
    active(nullable:true)
}

class AppIdentifier {

Date added
String authString

static belongsTo = [appDetail:AppDetail]

static constraints = {

    added()
    authString(blank:false)

}

def identifier = AppIdentifer.findByAuthString('test')
def appDetails = identifier.appDetail

您将authString都定义为String和AppDetail:

String authString

static belongsTo = [authString:AppDetail]

删除String authString或将其更改为AppDetail authString

顺便说一句,从GORM的角度来看,属性命名并不重要。 但是,如果您在名称中使用String定义了一个属性,而在另一个类中,则将来会遇到维护问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM