1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
@Override @Transactional (readOnly= true ) public Page<Question>
questionList( final String
keyword, final String
knowledge, final String
type, final String
itemBankId, final String
gradeId, final String
subjectId,Pageable pageable) { Page<Question>
question = questionDao.findAll( new Specification<Question>()
{ @Override public Predicate
toPredicate(Root<Question> root, CriteriaQuery<?> query, CriteriaBuilder cb) { Predicate
predicate = cb.conjunction(); List<Expression<Boolean>>
expressions = predicate.getExpressions(); if (StringUtils.isNotBlank(keyword))
{ expressions.add(cb.like(root.<String>get( "keyword" ), "%" +keyword+ "%" )); //关键字 } if (StringUtils.isNotBlank(knowledge))
{ expressions.add(cb.like(root.<String>get( "knowledge" ), "%" +knowledge
+ "%" )); //知识点 } if (NumberUtils.isDigits(type))
{ expressions.add(cb.equal(root.<String>get( "type" ),
type)); //l类型 } if (StringUtils.isNotBlank(itemBankId))
{ expressions.add(cb.equal(root.<String>get( "puuid" ),
itemBankId)); //父节点 } if (NumberUtils.isDigits(gradeId))
{ expressions.add(cb.equal(root.<Grade>get( "grade" ).<Long>get( "id" ),
NumberUtils.toLong(gradeId))); //年级 } if (NumberUtils.isDigits(subjectId))
{ expressions.add(cb.equal(root.<Subject>get( "subject" ).<Long>get( "id" ),
NumberUtils.toLong(subjectId))); //学科 } expressions.add(cb.equal(root.<Long>get( "deleteBy" ), 0 )); return predicate; } },pageable); return question; } |
Spring-data-jpa的动态查找案例
最新推荐文章于 2024-10-28 22:36:42 发布