У меня три параметра запроса в моем методе, и только если в теле запроса POST Http есть все три параметра availableCostTypesReturn,selectedCostTypesReturn and costTypeProgramId
, вызывается только этот метод.
Успешный запрос POST Body
availableCostTypesReturn=1&availableCostTypesReturn=2&availableCostTypesReturn=3&
availableCostTypesReturn=4&selectedCostTypesReturn=5&costTypeProgramId=53
Теперь, если мое тело запроса POST изменится на
availableCostTypesReturn=1&availableCostTypesReturn=2&availableCostTypesReturn=3&
availableCostTypesReturn=4&availableCostTypesReturn=5&costTypeProgramId=53
тогда этот метод не вызывается.
@RequestMapping(value = "/costTypes", method = RequestMethod.POST)
public String updateCostType(
Model model,
@RequestParam(value="availableCostTypesReturn")
String[] availableCostTypesReturn,
@RequestParam(value="selectedCostTypesReturn")
String[] selectedCostTypesReturn,
@RequestParam(value="costTypeProgramId")
int costTypeProgramId
)
Существуют сценарии, когда будет присутствовать только один из параметра availableCostTypesReturn, selectedCostTypesReturn.
Модифицировал подпись моего метода к этому
Так как я могу использовать тот же метод для этого.
Я использую Spring MVC 3.0.x
Изменена моя подпись аннотации в соответствии с ответом Томаша Нуркевича
@RequestParam(value="availableCostTypesReturn", defaultValue= "", required = false)