0

有没有办法确保 GORM 动态查找器中的空值安全?

如果我想做类似的事情Book.findByName(author.bookname),我可以通过将其更改为来防止空作者,Book.findByName(author?.bookname)但如何避免空值异常?

Book.findByName() is applicable for argument types: () values: []
4

1 回答 1

1

auther?.bookname ? Book.findByName(author.bookname) : null //or do nothing

根据示例中的事实,booknameNOT NULL.

或者你可以使用find

Book.find {name == author?.bookname} //Returns null if no records found

于 2013-04-24T21:09:45.417 回答