我的Grails应用程序有以下类
class Person {
Address address
// other attributes
}
class Address {
String street
City city
// more attributes
}
我想按街道名称的字母顺序查询前5个人。目前我做的事情是
def criteria = Person.createCriteria();
def people = criteria.list(max:5) {
address {
order("street","asc")
}
}
这很有效。我只是想知道是否有更短的方法(可能没有标准构建器)。
答案 0 :(得分:2)
实际上我认为这是最清晰,最有效的方式。你可以试试像executeQuery这样的东西,但说实话,我不确定这是不是那么冗长。如果您只是想缩短代码,可以简化前两行:
def people = Person.createCriteria().list(max:5) {
...