0

考虑这个域类:

class House {
  Integer room
  Integer bathroom
  Date builtDate
  Date boughtDate

  String roadName

  String getSearch(){
    return room + " " + bathroom + " " + builtDate + " " + boughtDate
  }
}

我想我的搜索机制有几个字段:按房间、浴室、builtDate、buyDate 搜索。

用户应该能够搜索这些参数的任意组合。他只能使用其中一个,或者全部使用。我需要一些关于我的控制器代码的帮助。我几乎可以肯定我不能使用 HQL 动态查找器来做到这一点,所以我必须使用 SQLS 语句。

任何帮助/提示将不胜感激。

4

1 回答 1

0

您可能想要使用休眠条件。类似于以下内容:

if (room && bathroom && builtDate && boughtDate) {
  House.withCriteria {
    if (room) {
      gte 'room', room
    }
    // ...
  }
}

查看有关 createCriteria 和 withCriteria 的文档以获取更多信息。

于 2011-07-01T14:11:39.080 回答