增加按帖子标题条件检索帖子

master
panqihua 5 years ago
parent 1d8162514d
commit 1ed7507181
  1. 11
      src/main/java/com/community/pocket/entity/vo/ForumQuery.java
  2. 4
      src/main/java/com/community/pocket/repository/android/ForumDao.java

@ -11,6 +11,9 @@ public class ForumQuery {
private Long currentPage;
//标题
private String title;
//用户名
private String username;
@ -59,4 +62,12 @@ public class ForumQuery {
public void setForumId(String forumId) {
this.forumId = forumId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}

@ -29,6 +29,7 @@ import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
/**
* 帖子数据接口
@ -102,6 +103,9 @@ public class ForumDao extends BaseDao<Forum> {
if (ObjectUtils.isNotEmpty(forumQuery.getForumType())) {
criteriaList.add(Criteria.where("forumType").in(forumQuery.getForumType()));
}
if (!StringUtils.isEmpty(forumQuery.getTitle())) {
criteriaList.add(Criteria.where("title").regex(Pattern.compile(".*" + forumQuery.getTitle() + ".*")));
}
Criteria criteria = new Criteria().andOperator(criteriaList.toArray(new Criteria[]{}));
long count = mongoTemplate.count(new Query(criteria), entityClass());

Loading…
Cancel
Save