|
@@ -95,12 +95,25 @@ public abstract class BaseMongodb<T> {
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public Long count(T entity) throws Exception {
|
|
|
+
|
|
|
+ return count(entity, getCollectionName());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据条件查询总数
|
|
|
+ *
|
|
|
+ * @param entity 查询对象
|
|
|
+ * @param collectionName 查询collection名称
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public Long count(T entity, String collectionName) throws Exception {
|
|
|
Query query = beanForQuery(entity);
|
|
|
long count = 0;
|
|
|
- if (getCollectionName() == null) {
|
|
|
- count = getMongoTemplate().count(query, getEntity());
|
|
|
+ if (collectionName == null) {
|
|
|
+ count = getMongoTemplate().count(query, getEntity(), collectionName);
|
|
|
} else {
|
|
|
- count = getMongoTemplate().count(query, getEntity(), getCollectionName());
|
|
|
+ count = getMongoTemplate().count(query, getEntity(), collectionName);
|
|
|
}
|
|
|
return count;
|
|
|
}
|