且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JPA Repository findAll 带有可选字段

更新时间:2023-01-16 08:53:52

我认为您不能使用 example 通过 id 查找记录.(这是非常合乎逻辑的,如果您知道 id,那么您为什么完全需要此功能?)

I think you cannot use the example to find records by id. (Which is quite logical, if you know the id then why do you need this feature at all?)

因此,如果请求中提供了 id 参数,则直接使用 findById(id)否则 填充示例对象的所有提供的属性并使用 findAll(Example.of(example)) 方法.

So if the id parameter is provided in the request then use findById(id) directly, otherwise fill all the provided properties of an example object and use the findAll(Example.of(example)) method.