English 中文(简体)
Grails: How to exercise actions when a territorial category property is set in GORM
原标题:Grails: how to perform action when a Domain Class property is set in GORM

无论采取什么方式,都有必要采取行动。 这是我所希望的工作,是否还有其他可能的办法?

行业:

Class ExampleDomain {
  BigDecimal someNumber
  def setSomeNumber = {setVal ->
    println "Today is a good day to be the number: ${setVal}"
  }

}

我只能对<代码>onUpdate上的事件以及像现在这样或现在有办法改变 Java物体驱动活动?

例如:

def thisThing = new ExampleDomain(someNumber:3.0) //prints "Today is a good day to be the number: 3.0"
thisThing.someNumber = 5.8  //prints "Today is a good day to be the number: 5.8"
thisThing.save()  //prints nothing

这种可能的行为吗?

最佳回答

你们可以这样做,确定宽松/优良的方法,而不是关闭:

Class ExampleDomain {
  BigDecimal someNumber

  void setSomeNumber(someNumber) {
    println "Today is a good day to be the number: ${someNumber}"
    this.someNumber = someNumber
  }

  BigDecimal getSomeNumber() {
    someNumber
  }
}

著作

//prints "Today is a good day to be the number: 5.8"
new ExampleDomain().someNumber = 5.8  
问题回答

暂无回答




相关问题
Groovy - how to exit each loop?

I m new to Grails/Groovy and am trying to find a node in a an xml file; I ve figured out how to iterate over all of them, but I want to exit the loop when the target node is found. I ve read that ...

Eclipse Spring Builder set properties with Groovy beans

I typically use groovy to construct simple bean but the Spring IDE plugin to eclipse fails to build when I try to set a property that is generated by groovy without an explicit setter. For example, ...

How can I get this snippet to work?

I d like to port a little piece of code from Ruby to Groovy, and I m stuck at this: def given(array,closure) { closure.delegate = array closure() } given([1,2,3,4]) { findAll { it > 4} ...

Changing the value in a map in Groovy

This is about a very basic program I m writing in Groovy. I have defined a map inside a method: def addItem() { print("Enter the item name: ") def itemName = reader.readLine() print(...

Is functional Clojure or imperative Groovy more readable?

OK, no cheating now. No, really, take a minute or two and try this out. What does "positions" do? Edit: simplified according to cgrand s suggestion. (defn redux [[current next] flag] [(if flag ...

热门标签