当我们为topRequest和forward请求具有相同的参数名时,Spring MVC转发附加请求参数值以逗号分隔

时间:2017-04-13 21:46:23

标签: spring spring-mvc

当我们为topRequest和转发请求具有相同的参数名称时,Spring MVC转发附加请求参数值以逗号分隔

@RequestMapping(path = "/details")
public ModelAndView details(@ModelAttribute final DetailsForm detailsForm){
  //DetailsForm contain a parameter called destinationId with value 1234
  final ModelAndView mav = new ModelAndView();
  //Some logic to get targeted destinationId (7890) using destinationId (1234) from detailForm
  mav.setViewName("forward:/search?destinationId=7890");
  return mav;
}

@RequestMapping(path = "/search")
    public ModelAndView details(@ModelAttribute final SearchForm searchForm){
  //Here I tried to get destinationId from model-attribute searchForm
  final Integer destinationId = searchForm.getDestinationId();
  //Then it returned me 1234,7890
}

有人可以帮我解决这个问题。我想只得到7890。

1 个答案:

答案 0 :(得分:0)

我也对答案感兴趣。我也通过添加一个方法来解决这个问题:

private String getLastPartFromFormValue(final String value) {
    if (value == null)
        return null;
    String[] parts = value.split(",");
    return parts[parts.length -1];
}