How to return using if else using Lambda expression ?
public static Specification<Employee> textInAllColumns(Object value) {
if (value instanceof String) {
return (root, query, builder) -> builder
.or(root.getModel().getDeclaredSingularAttributes().stream()
.filter(a -> {
return a.getJavaType()
.getSimpleName()
.equalsIgnoreCase("String") ? true : false;
})
.map(a -> builder.like(root.get(a.getName()), getString((String) value)))
.toArray(Predicate[]::new));
} else if (value instanceof Integer) {
return (root, query, builder) -> builder
.or(root.getModel().getDeclaredSingularAttributes().stream()
.filter(a -> {
return a.getJavaType()
.getSimpleName()
.equalsIgnoreCase("Integer") ? true : false;
})
.map(a -> builder.equal(root.get(a.getName()), value))
.toArray(Predicate[]::new));
}
}
I am getting below error:
This method must return a result of type Specification
@GetMapping("/findEmployees")
public ResponseEntity<List<Employee>> findEmployees(@RequestParam Object searchValue) {
List<Employee> employees = employeeService.searchGlobally(searchValue);
return new ResponseEntity<>(employees, HttpStatus.OK);
}