JPA分页+条件查询的问题
service代码如下
//websiteservice
public Page<Website> findPage(Integer page, Integer size, String name, String url) {
Pageable pageable = (Pageable) new PageRequest(page, size);
return websiteRepository.findAll(new Specification<Website>() {
@Override
public Predicate toPredicate(Root<Website> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
Path<String> namePath = root.get("name");
Path<String> urlPath = root.get("url");
/**
* 连接查询条件, 不定参数,可以连接0..N个查询条件
*/
query.where(cb.like(namePath, "%" + name + "%"), cb.like(urlPath, "%" + url + "%")); //这里可以设置任意条查询条件
return null;
}
}, pageable);
}
//economyservice
public Page<Economy> findPage(Integer page, Integer size, String data_type) {
Pageable pageable = (Pageable) new PageRequest(page, size);
return economyRepository.findAll(new Specification<Economy>() {
@Override
public Predicate toPredicate(Root<Economy> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
Path<String> dataTypePath = root.get("data_type");
/**
* 连接查询条件, 不定参数,可以连接0..N个查询条件
*/
query.where(cb.like(dataTypePath, "%" + data_type + "%")); //这里可以设置任意条查询条件
return null;
}
}, pageable);
}
2个service代码是差不多的但是只有economy的生效了
Hibernate: select count(economy0_.id) as col_0_0_ from t_economy economy0_ where economy0_.data_type like ?
Hibernate: select economy0_.id as id1_0_, economy0_.area as area2_0_, economy0_.data_time as data_tim3_0_, economy0_.data_type as data_typ4_0_, economy0_.data_value as data_val5_0_ from t_economy economy0_ where economy0_.data_type like ? limit ? offset ?
Hibernate: select count(website0_.id) as col_0_0_ from t_website website0_ where (website0_.name like ?) and (website0_.url like ?)
从上面打印的sql来看应该是website少执行了一条sql,但是调用的方法都是一样的,为什么会出现个这个情况啊?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论