I have an entity which has multiple property paths. I used Query By Example and ExampleMatcher to ignore some of the property path.
My entity looks like below, Employee.class
private Integer id;
private String name;
private String designation;
I wanted to show only the Name and Id from the entity(fields in the table). For that, I did the following,
ExampleMatcher exampleMatcher = ExampleMatcher.matching().withIgnoreNullValues().withIgnorePaths("designation");
Example<Employee> example = Example.of(entity, exampleMatcher);
But, the response returns all the values including the property given in the ignorePath.
Kindly assist me on how to ignore the property paths.
A generic property matcher that specifies string matching and case sensitivity. static class. ExampleMatcher.GenericPropertyMatchers. Predefined property matchers to create a ExampleMatcher.
Query by Example (QBE) is a method of query creation that allows us to execute queries based on an example entity instance. The fields of the entity instance need to be populated with the desired criteria values.
withIgnorePaths("designation")
prevents query-by-example from applying a filter based on the example's designation
value. It does not prevent designation
from being populated in the query result.
If you want to exclude certain properties from the query result, use projections or query graphs (depending on which is a better fit for your particular use case). Not sure if there's a way they can be used with query-by-example, though.
Am not sure if this will work
ExampleMatcher exampleMatcher = ExampleMatcher.matching().withIgnorePaths("designation").withIgnoreNullValues();
I just added withIgnorePaths
first.
Refering to This link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With