【发布时间】:2017-12-13 04:53:15
【问题描述】:
我想使用spring JPA规范的join函数
这是我的表格代码:
- 表学生
-
父级表
public static Specification<InStudent> filterByKeywordAndStatus(final String keyword) { return (Root<InStudent> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> { List<Predicate> predicates = new ArrayList<>(); if (StringUtils.hasText(keyword)) { predicates.add( cb.or( cb.like(root.get(InStudent_.name), "%" + keyword + "%"), cb.like(root.get(InStudent_.address), "%" + keyword + "%"), cb.like(root.get(InStudent_.phone), "%" + keyword + "%") ) ); } return cb.and(predicates.toArray(new Predicate[predicates.size()])); };}
如何在规范中加入表 inStudent 和 inParent?
【问题讨论】:
-
您没有在代码中包含关系。无论如何使用连接就像
Join<InStudent, InParent> parent = root.join(InStudent_.parent);假设指定关系的字段是parent。 -
您好,如果回答对您有帮助,别忘了接受/点赞。
标签: java jpa spring-boot spring-data-jpa