(快速參考)

clearErrors

目的

重設網域類別上的錯誤清單。這在網域類別因繫結問題或驗證問題而包含錯誤時可能很有用。錯誤可以透過程式設計進行修正。除非清除錯誤,否則驗證可能會持續失敗。

範例

def b = new Book(title: "The Shining")
b.validate()
if (b.hasErrors()) {

    // clear the list of errors
    b.clearErrors()

    // fix the validation issues
    b.author = "Stephen King"

    // re-validate
    b.validate()
}