myBeanClass.java
public class KeywordsPagination {
private int contentId;
private int size;
private int page;
public int getSize() {
return size;
}
public int getContentId() {
return contentId;
}
public void setContentId(int contentId) {
this.contentId = contentId;
}
public void setSize(int size) {
this.size = size;
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
我正在传递内容ID。该内容ID基础上获得关键字。基于关键字我正在搜索数据库。我想获取相关的关键字列表
服务实施:
Keywords key = keyWordsRepository.findAllByContentId(keywordsPagination.getContentId());
String keywords = key.getKeywords();
keyWords = keywords.split(",");
for (int i = 0; i < keyWords.length; i++) {
name = keyWords[i];
// names=name;
System.out.println("names"+name.toString());
list = keywordsCallBack.getListofcontentId(keywordsPagination.getContentId(), name, pageable);
}
这是我的代码
**DetachedCriteria.java**
@SuppressWarnings({ "deprecation", "unchecked" })
@Override
public List<Keywords> getListofcontentId(int contentId, String[] keyWords, Pageable pageable) {
List<Keywords> list = null;
Criteria criteria = getSession().createCriteria(Keywords.class, "key");
criteria.createAlias("key.content", "con");
for (int i = 0; i < keyWords.length; i++) {
criteria.add(Restrictions.eq("ke.keywords", keyWords));
System.out.println("criteria "+criteria );
list = criteria.list();
}
return list;
}
这是我的条件查询