我的方法中有三个请求参数,只有当Http POST请求体具有全部三个参数availableCostTypesReturn,selectedCostTypesReturn and costTypeProgramId
时才会调用此方法。
成功的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
根据Tomasz Nurkiewicz的答案修改我的注释签名
@RequestParam(value="availableCostTypesReturn", defaultValue= "", required = false)
答案 0 :(得分:2)
尝试@RequestParam
设置为false
的{{3}}属性:
@RequestMapping(value = "/costTypes", method = RequestMethod.POST)
public String updateCostType(
Model model,
@RequestParam(value="availableCostTypesReturn", required = false)
String[] availableCostTypesReturn,
@RequestParam(value="selectedCostTypesReturn", required = false)
String[] selectedCostTypesReturn,
@RequestParam(value="costTypeProgramId", required = false)
int costTypeProgramId
)