3

新しい値が以前の値よりも 0.50 大きくなるように、ドメイン クラスで変数 'amount' のカスタム バリデータを作成しようとしています。

たとえば、前回の値が 1.0 だったとします。次回は少なくとも [前回の値 + 0.50] 以上の値にする必要があります。

助けてくれてありがとう

4

2 に答える 2

4

あなたは読んでみることができますdomainEntity.getPersistentValue('amount')

編集: ...カスタムバリデーターで、次のように:

class Bid { 
  Double amount 
  ...
  static constraints = { amount(validator: { double a, Bid b -> 
    def oldValue = b.getPersistentValue('amount')
    a > oldValue + 0.5 ? true : "Amount $a should be at least ${oldValue  + 0.5}" }) 
  }
}
于 2011-02-15T16:06:18.523 に答える
0

Thx Victor Sergienko、しかし私はあなたのコードを少し変更します

class Bid { 
  Double amount 
  ...
  static constraints = { amount(validator: { double a, Bid b -> 
    Bid tempBid = Bid.get(b.id)
    def oldValue = tempBid.getPersistentValue('amount')
    a > oldValue + 0.5 ? true : "Amount $a should be at least ${oldValue  + 0.5}" }) 
  }
}

違いは次の行にあります。

Bid tempBid = Bid.get(b.id)
def oldValue = tempBid.getPersistentValue('amount')

b.getPersistentValue('amount')常に null 値を返す理由はわかりません。私の grails のバージョンは 2.4.3 です。

于 2015-01-27T06:59:32.633 に答える