Я хочу реализовать REST API на Java с «перегруженной» конечной точкой, которая отличается переданными параметрами запроса.
Я пробовал этот код в своем классе контроллера:
@Get("/query")
public MyResponse queryByDate(@QueryValue @Valid @Format("yyyy-MM-dd") Date date) {
// Code to generate the response
return retval;
}
@Get("/query")
public MyResponse queryByDateAndValue(@QueryValue @Valid @Format("yyyy-MM-dd") Date date, @QueryValue int value) {
// Code to generate the response
return retval;
}
Это возвращает следующую ошибку:
More than 1 route matched the incoming request. The following routes matched /calendar/years/query: GET - /calendar/years/query, GET - /calendar/years/query
io.micronaut.web.router.exceptions.DuplicateRouteException: More than 1 route matched the incoming request. The following routes matched /calendar/years/query: GET - /calendar/years/query, GET - /calendar/years/query
Обратите внимание: если я удалю один из методов, оставшийся метод будет работать должным образом. Как я могу сопоставить конечную точку с разными параметрами запроса с двумя разными методами в контроллере? Это возможно?
Спасибо.