我在spring boot中有一个get方法这是我的服务:
public List<Customer> getAllCustomers() {
List<Customer> customers = cutomerRepository.findAll();
return customers;
}
这个Api返回所有客户,但是如果我需要过滤他们呢?其中一个包含X
的例子:
{
"id": 1,
"firstName": "rorororo",
"lastName": "dfdfkd",
"email": "gfhgfhdgfdh@kjkr",
"mobileNumber": null,
"invoices": null,
"name": "rorororo",
"deleted": false
}
这是json的形状,我需要返回的地方删除= false,当它等于真,而不是返回它…
使用spring-data-jpa,您可以通过向存储库添加方法(使用一组关键字)来编写您自己的查询。
对于示例return customers where deleted = false
,您可以编写以下方法:
List<Customer> findByDeletedFalse();