Recommand · May 14, 2022 0


What is the best practice for solving the number of cases of N searches in Spring JPA?

What is the best practice for solving the number of cases of N searches?

There are 3 search conditions for me. There are search conditions of A, B, and C.

In this case, the number of possible cases is Search only A, search only B, search only C, Search only AB, search only AC, search only BC Search only ABC

In the above situation, there are a total of 6 cases like this.(3!)

To map the number of all cases without thinking

@GetMapping("/A/{A}/B/{B}/C/{C}")
public ReturnType MethodName(@PathVariable AClass A
                             @PathVariable BClass B,
                             @PathVariable CClass C) {
return service.findByAandBandC(A, B, C);

I have to create 6 controller methods like the one above.

With 4 search conditions, need 24 methods (4! = 4 * 3 * 2)

If there are 5 search conditions, need 120 methods (5! = 5 * 4 * 3 * 2)

As above, it grows exponentially.

Instead of making all cases a method, I wonder if there is a best practice.

If possible, any answer utilizing spring data jpa would be appreciated.

best regards!




You may also like…




amazon-web-services android angular api arrays c# css dart dataframe django docker excel express firebase flutter html ios java javascript jquery json kotlin laravel linux list mongodb mysql node.js pandas php postgresql python python-3.x r react-native reactjs regex spring spring-boot sql sql-server string swift typescript vue.js