标题:
java-spring与mongodb的整合方式一 自动注入xml(7)
[打印本页]
作者:
look_w
时间:
2019-4-19 19:42
标题:
java-spring与mongodb的整合方式一 自动注入xml(7)
特殊查询用法积累:
添加在UserReposityImpl中
1.增加排序
public List<User> getByLinkUrlId(int begin, int end, String linkUrlid,String orderField,Sort.Direction direction ) {
Query query = new Query();
query.addCriteria(Criteria.where("pageUrl.linkUrl.id").is(linkUrlid));
return find(query.limit(end - begin).skip(begin).with(new Sort(new Sort.Order(direction, orderField))),User.class);
}
2.按时间段查询
public List<Log> getLogs(List<Condition> conditions,String beginDate,String endDate)
{
Query query = new Query();
if (conditions != null && conditions.size() > 0) {
for (Condition condition : conditions) {
query.addCriteria(Criteria.where(condition.getKey()).regex(
".*?\\" +condition.getValue()+ ".*"));
}
}
query.addCriteria(Criteria.where("crawlTime").lt(new Date(endDate)).gt(new Date(beginDate)));
return find(query,Log.class);
}
3.或者查询
Criteria criteria = new Criteria();
if (!StringUtils.isEmpty(data.get("name"))) {
criteria.orOperator(
Criteria.where("name").regex(
".*" + data.get("name") + ".*", "i"),
Criteria.where("chromosome").regex(
".*" + data.get("name") + ".*", "i"));
}
Query query = Query.query(criteria);
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/)
Powered by Discuz! 7.0.0