grails中缺少PropertyException
当我试图显示我的一个域的视图时出现问题。我建立了一个求和一些数量的方法,但我有这个错误,我不知道如何修复它。我知道可变奖励不存在,但我在我的领域中有这个价值。这是控制器中唯一给出错误的方法的代码grails中缺少PropertyException,grails,grails-domain-class,grails-controller,grails-services,Grails,Grails Domain Class,Grails Controller,Grails Services,当我试图显示我的一个域的视图时出现问题。我建立了一个求和一些数量的方法,但我有这个错误,我不知道如何修复它。我知道可变奖励不存在,但我在我的领域中有这个价值。这是控制器中唯一给出错误的方法的代码 URI /Rewards/customer/show/1 Class groovy.lang.MissingPropertyException Message No such property: awards for class: rewards.Customer Around line 14 of
URI /Rewards/customer/show/1
Class groovy.lang.MissingPropertyException
Message No such property: awards for class: rewards.Customer
Around line 14 of grails-app/services/rewards/CalculationsService.groovy
11:
12: def getTotalPoints(customerInstance){
13: def totalAwards = 0
14: customerInstance.awards.each{
15: totalAwards = totalAwards + it.points
16: }
17: customerInstance.totalPoints = totalAwards
Around line 33 of grails-app/controllers/rewards/CustomerController.groovy
30:
31: def show(Long id){
32: def customerInstance = Customer.get(id)
33: customerInstance = calculationsService.getTotalPoints(customerInstance)
34: [customerInstance: customerInstance]
35: }
36:
控制器(CustomerController.groovy)
模特儿
class Customer {
String firstName
String lastName
Long phone
String email
Integer totalPoints
static hastMany = [awards:Award, orders:OnlineOrder]
static constraints = {
phone()
firstName(nullable: true)
lastName(nullable: true)
email(nullable: true, email: true)
totalPoints(nullable: true)
}
}
模范奖
package rewards
class Award {
Date awardDate
String type
Integer points
static belongsTo = [customer:Customer]
static constraints = {
}
}
服务(CalculationService.groovy)
您在客户域中拼写的
有许多
错误
static hastMany = [awards:Award, orders:OnlineOrder]
应该是
static hasMany = [awards:Award, orders:OnlineOrder]
您能提供模型客户的代码吗?模型客户类客户{String firstName String lastName Long phone String email Integer totalPoints static hastMany=[awards:awards,orders:OnlineOrder]静态约束={phone()firstName(null:true)lastName(nullable:true)email(nullable:true,email:true)totalPoints(nullable:true)}尝试运行grails clean,看看它是否有帮助否,我清理了项目,但我有相同的错误您添加了“奖励”吗属性?您是否在数据库中插入了没有此属性的客户?如果是,您需要清理数据库
static hastMany = [awards:Award, orders:OnlineOrder]
static hasMany = [awards:Award, orders:OnlineOrder]