Complete the code to create a Specification that checks if a field equals a value.
Specification<User> spec = (root, query, criteriaBuilder) -> criteriaBuilder.[1](root.get("username"), "john");
The equal method creates a condition to check if the field matches the given value exactly.
Complete the code to combine two Specifications with AND logic.
Specification<User> combinedSpec = spec1.[1](spec2);The and method combines two specifications so both conditions must be true.
Fix the error in the Specification to check if age is greater than 18.
Specification<User> adultSpec = (root, query, criteriaBuilder) -> criteriaBuilder.[1](root.get("age"), 18);
The greaterThan method checks if the field value is greater than the given number.
Fill both blanks to create a Specification that checks if status is 'ACTIVE' and email contains 'example.com'.
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%"));
Use equal to check exact status and and to combine both conditions.
Fill all three blanks to create a Specification that filters users with age greater than 25, name starting with 'A', and active status.
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"));
Use greaterThan for age, and to combine, and .and to chain the last condition.