如何进行动态 Grails 搜索?
考虑这个域类:
class House {
Integer room
Integer bathroom
Date builtDate
Date boughtDate
String roadName
String getSearch(){
return room + " " + bathroom + " " + builtDate + " " + boughtDate
}
}
我想象我的搜索机制有几个字段:按房间、浴室、builtDate、buyDate 搜索。
用户应该能够搜索这些参数的任意组合。他可以只使用其中之一,也可以使用全部。我的控制器代码需要一些帮助。我几乎可以肯定我无法使用 HQL 动态查找器来做到这一点,所以我必须使用 SQLS 语句。
任何帮助/提示将不胜感激。
Consider this domain class:
class House {
Integer room
Integer bathroom
Date builtDate
Date boughtDate
String roadName
String getSearch(){
return room + " " + bathroom + " " + builtDate + " " + boughtDate
}
}
I imagine having several fields for my search mechanism: search by room, bathroom, builtDate, boughtDate.
The user should be able to search for any combination of these paramaters. He can use only one, or all of them. I need some help with my controller code. I'm almost sure I cannot do that using HQL Dynamic Finders so I'll have to use SQLS statments.
Any help/hint would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想使用休眠标准。大致内容如下:
查看 createCriteria 和 withCriteria 上的文档以获取更多信息。
You probably want to use a hibernate criteria. Something along the lines of:
Look at the docs on createCriteria and withCriteria for more information.