0
0
Spring Bootframework~10 mins

Specification pattern for dynamic queries in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a Specification that checks if a field equals a value.

Spring Boot
Specification<User> spec = (root, query, criteriaBuilder) -> criteriaBuilder.[1](root.get("username"), "john");
Drag options to blanks, or click blank then click option'
AnotEqual
Blike
CgreaterThan
Dequal
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'like' instead of 'equal' for exact match.
Using 'greaterThan' which is for numeric comparisons.
2fill in blank
medium

Complete the code to combine two Specifications with AND logic.

Spring Boot
Specification<User> combinedSpec = spec1.[1](spec2);
Drag options to blanks, or click blank then click option'
Anot
Bor
Cand
Dequals
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'or' which allows either condition to be true.
Using 'not' which negates a specification.
3fill in blank
hard

Fix the error in the Specification to check if age is greater than 18.

Spring Boot
Specification<User> adultSpec = (root, query, criteriaBuilder) -> criteriaBuilder.[1](root.get("age"), 18);
Drag options to blanks, or click blank then click option'
AgreaterThan
Bequal
ClessThan
Dlike
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'equal' which checks for exact match.
Using 'like' which is for strings.
4fill in blank
hard

Fill both blanks to create a Specification that checks if status is 'ACTIVE' and email contains 'example.com'.

Spring Boot
Specification<User> spec = Specification.where((root, query, criteriaBuilder) -> criteriaBuilder.[1](root.get("status"), "ACTIVE")).[2]((root, query, criteriaBuilder) -> criteriaBuilder.like(root.get("email"), "%example.com%"));
Drag options to blanks, or click blank then click option'
Aequal
Bor
Cand
Dnot
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'or' instead of 'and' which changes logic.
Using 'not' which negates conditions.
5fill in blank
hard

Fill all three blanks to create a Specification that filters users with age greater than 25, name starting with 'A', and active status.

Spring Boot
Specification<User> spec = Specification.where((root, query, criteriaBuilder) -> criteriaBuilder.[1](root.get("age"), 25)).[2]((root, query, criteriaBuilder) -> criteriaBuilder.like(root.get("name"), "A%"))[3]((root, query, criteriaBuilder) -> criteriaBuilder.equal(root.get("status"), "ACTIVE"));
Drag options to blanks, or click blank then click option'
AgreaterThan
Band
C.and
D.or
Attempts:
3 left
💡 Hint
Common Mistakes
Missing dot before 'and' in chaining.
Using 'or' which changes filter logic.