@RestController @RequestMapping(value = "/players") public class REST { @RequestMapping(method = RequestMethod.GET) public List<Player> getAll() { return service.getAll(); } @RequestMapping(method = RequestMethod.GET, params = {"team", "score"}) public List<Player> getByPlayerAndScore(@RequestParam(value = "team") String team, @RequestParam(value = "score", required = false) int score) { return service.getByPlayerAndScore(team, score); } } Q1: I am expecting first method to work for url "/players" (worked as expected) and second method to work for url's ("/players?team=xyz", "/players?team=xyz&score=1000"). spring used method1 for "/players?team=xyz". Even i specified score as optional, unless i specify 2 params, spring is is not using 2nd method. How to solve this and what is best way of writing controller methods to handle these type of requests where user can send different sets of available params (like param1¶m2, only param1, only param2 etc).
Q2: For the 2nd type of query with different sets of params, how to write database queries in DAO layer. should i write separate methods each with a different query or one method with multiple if statements(like if user sent 'team' add team to DB query, if user sent 'score' add it to DB query ...)