2
我有三個請求參數在我的方法,並且只有當Http POST請求主體有全部三個參數availableCostTypesReturn,selectedCostTypesReturn and costTypeProgramId
那麼只有這個方法被調用。在Spring MVC映射方法沒有得到調用,當requestparam不存在後
成功POST請求主體
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的
修改我的標註簽名按答案從托馬斯Nurkiewicz
@RequestParam(value="availableCostTypesReturn", defaultValue= "", required = false)