1

当我尝试显示我的一个域的视图时遇到问题。我建立了一个方法来总结一些数量,但我有这个错误,我不知道如何解决它。我知道可变奖励不存在,但我在我的域中有这个值。这是控制器中唯一给我错误的方法的代码。

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)

package rewards

class CustomerController {
    static scaffold = true

    def calculationsService

    def show(Long id){
        def customerInstance = Customer.get(id)
        customerInstance = calculationsService.getTotalPoints(customerInstance)
        [customerInstance: customerInstance]
    }

模特顾客

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 = {
    }
}

服务(CalculationsService.groovy)

package rewards

import grails.transaction.Transactional

@Transactional
class CalculationsService {


    def serviceMethod() {

    }

    def getTotalPoints(customerInstance){
        def totalAwards = 0
        customerInstance.awards.each{
            totalAwards = totalAwards + it.points
        }
        customerInstance.totalPoints = totalAwards
        return customerInstance
    }
}
4

1 回答 1

1

hasMany在客户域中拼写错误。

static hastMany = [awards:Award, orders:OnlineOrder]

应该

static hasMany = [awards:Award, orders:OnlineOrder]
于 2015-04-29T14:51:13.710 回答