2014-09-22 23 views
1

我必須驗證eventId的這個值是否已經存在於mysql database.i中有一個事件數據庫,其中的id存儲在event_id中。所以我需要驗證這個eventId已經存在與否。在域類中的驗證

域類:

class Event { 
      String eventId 
      static constraints = { 
       eventId(blank: false,nullable: false) 
       eventId validator: {val -> 
         if(val== event.event_id){ 
         return false 
        } 
     } 

回答

1

您應該使用的Grails

e.g提供了獨特的約束

static constraints = { 
    eventId unique: true 
}