Grails 使用带有 3x+ 的动态查找器逻辑论证
我成功地使用 Hibernate 的动态查找器在数据库中进行搜索:
def temp = User.findByNameAndStreet("name", "street")
尽管如此,我需要一个像这样的三重逻辑参数:
def temp = User.findByNameAndStreetAndCity("name", "street", "city")
有什么简单的方法可以做到这一点吗?
I sucessfully managed to search in the database using this dynamic finder from Hibernate:
def temp = User.findByNameAndStreet("name", "street")
Although, i need a tripple logical argument like this:
def temp = User.findByNameAndStreetAndCity("name", "street", "city")
Any simple way to do it ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Grails 动态查找器不支持两个以上的谓词。这是因为不清楚是否
意味着 this:
或 this:
不可否认,如果谓词始终与
And
或Or
组合。更新:从 Grails 1.4 开始,如果谓词全部与
And
或Or
组合,则可以拥有无限数量的谓词,相反,您可以使用
findWhere
或findAllWhere
(取决于您是只想要第一个结果还是所有结果)。这两个都支持无限数量的谓词,我假设这些谓词与And
组合,例如:The Grails dynamic finders don't support more than two predicates. This is because it's not clear whether
means this:
or this:
Admittedly if the predicates are always combined with
And
orOr
.Update: since Grails 1.4 you can have an unlimited number of predicates if they're all combined with either
And
orOr
Instead, you can use either
findWhere
orfindAllWhere
(depending on whether you want just the first result or all results). Both of these support an unlimited number of predicates which I assume are combined withAnd
, for example: