本文介绍了Grails标准预测 - 获取行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有Hotel实体:
class Hotel {
City city
}
现在,我需要计算给定城市的酒店数量。
可以这样做:
def hotels = Hotel.findAllByCity(city)
def cnt = hotels.size()
但它非常脏。它似乎与标准,它会更好,但我不知道如何实现它...
解决方案
有动态计数器以及域对象上的查找器:
Hotel.countByCity(city)
更多详情请参阅,当然
I have Hotel entity:
class Hotel {
City city
}
Now, i need count of hotels with given city.It could be done in this way:
def hotels = Hotel.findAllByCity(city)
def cnt = hotels.size()
But it's very dirty way. It seems that with criteria it would be better, but i have no idea how to implement it...
解决方案
There are dynamic counters as well as finders on domain objects:
Hotel.countByCity(city)
More details in the user guide, of course
这篇关于Grails标准预测 - 获取行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!