I am working on Angular 2 with a Spring Boot application, and I am passing some search parameters through my UI to SpringBoot RestController where I am using the CrudRepository<User, id> interface for CRUD operations and am using some methods like findByValue(), but in my app I have four search boxes, like name, age, city, and country.
If I fill only two boxes then I would like to search for that given two parameters like Age=22, City=New York then only those people who lives in New York with age 22 should be as result if I add name also like name=James then it should search with name and age 22 and city New York.
How do I achieve this kind of functionality in my SpringBoot with a Angular 2 app?
Repository Class:
public interface UserRepository extends CrudRepository<User, Integer> {
public List<User> findAll();
public List<User> findByName(String name);
}
My Controller Code:
@CrossOrigin(origins = "http://localhost:4200", maxAge = 3600)
@RequestMapping(value = "/user/list", method=RequestMethod.POST)
public List<User> getRequestedUsers(@RequestBody User userObject) {
return userRepository.findByAllParam();
// I want to write some method here to get data with all or may be 3, 2, or 1 parameters
}