I have a get method in spring boot this is my service :
public List<Customer> getAllCustomers() {
List<Customer> customers = cutomerRepository.findAll();
return customers;
}
This Api return All customers, but what about if i need to filtering them ? where one of them contains X
example :
{
"id": 1,
"firstName": "rorororo",
"lastName": "dfdfkd",
"email": "gfhgfhdgfdh@kjkr",
"mobileNumber": null,
"invoices": null,
"name": "rorororo",
"deleted": false
}
This is the shape of json, and i need to return where deleted = false and when its equal true, not returing it ...
CodePudding user response:
With spring-data-jpa, you can write your own queries by adding methods (using a set of keywords) to your repository.
For your example return customers where deleted = false
, you can write the following method :
List<Customer> findByDeletedFalse();