0
的什么,我试图做一个例子里面过滤器:防止结膜标准声明
def authorName = "John Smith"
def books = Book.createCriteria().list() {
eq('genre', 'fiction')
eq('publishDate', '2007')
if(authorName != null){
Author author = Author.findWhere(name: authorName)
if(author == null) //what do I do here?
else { eq('authorId', author.id }
}
}
如果没有笔者给定id,那么笔者不存在(假设:这不是什么t删除),因此没有作者写的书。评估应该在那里停止并且不返回任何结果。我可以用什么来实现这个目标?
第二部分看起来像我想要的。你是在哪里找到那个东西的。 – mowwwalker
我没有真正“找到”它的任何地方。我一直在与Grails合作7年或8年,并熟悉标准API。官方用户指南涵盖了很好的可能性。请参阅http://grails.org/doc/latest/guide/GORM.html#criteria。 –