classPublication{StringtitleStringauthorDatedatePublishedIntegernumberOfPagesstaticnamedQueries={recentPublications{defnow=newDate()gt'datePublished',now-365}oldPublicationsLargerThan{pageCount->defnow=newDate()lt'datePublished',now-365gt'numberOfPages',pageCount}publicationsWithBookInTitle{like'title','%Book%'}recentPublicationsWithBookInTitle{// calls to other named queries…recentPublications()publicationsWithBookInTitle()}}}defbooks=Publication.recentPublications.list(max:10,offset:5){//可加入其他規則or{like'author','Tony%'like'author','Phil%'}}
Book.createCriteria().list(max:10,offset:10){title(delegate,'Harry Potter%')author(delegate,'J. K. Rowling')//可加入其他規則}privatevoidtitle(builder,Stringtitle){builder.ilike'title',title}privatevoidauthor(builder,StringauthorName){builder.eq'author',authorName}