I am currently working on an application that utilizes Java with the Spring framework and Javascript with AngularJs framework. The application features a table displaying a list of objects along with two text fields for filtering these objects. The filtering process occurs on the server side, where I pass the values from the text fields to the @RestController's method as parameters, and then to the repository method. On the client side:
$http({
method: 'GET',
url: '/messages',
params: {sender: $scope.sender, recipient: $scope.recipient}
}).then(
function (res) {
$scope.messages = res.data;
},
function (res) {
console.log("Error: " + res.status + " : " + res.data);
}
);
Server side:
@GetMapping("/messages")
@ResponseBody
public List<Message> getMessagesWithFilters(@RequestParam(required = true) String sender,
@RequestParam(required = true) String recipient) {
List<Message> messages = messageRepository.findBySenderNumberAndRecipientNumber(sender, recipient);
return messages;
}
Dealing with just two filters is manageable, but what should be my approach if there are 10 or even 20 filters in play? Are there more efficient ways to handle this, like passing them as a Map or another method?