@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 expect the first method to work for URLs / players (works as expected) and the second method to work for URLs ("/ players? Team = xyz", "/ players? Team = hoog & score = 1000 "). spring uses method1 for "/ players? team = xyz". Even I indicated the evaluation as optional, unless I specify 2 parameters, spring does not use the second method. How to solve this and how best to write controller methods for processing requests of this type where the user can send different sets of available parameters (for example, param1 and param2, only param1, only param2, etc.).
Q2: , DAO. if (, " " , "", ...)