我试图将一个String []从客户端发布到Spring 3.在Controller方面,我已经定义了这样的方法。
@RequestMapping(value = "somemethod", method = RequestMethod.POST)
public ModelAndView exportSomething(@RequestParam("sentences") String[] sentences) {
//.. logic
}
我发送的数据看起来像这样
sentences: ["a","b,c","d"]
问题是在服务器端,句子数组的大小是4.它将b和c分成两个不同的单词。
这是Spring的问题还是我需要按照传递数据的方式进行更改?
答案 0 :(得分:3)
我想用Spring框架知道它的问题。见https://jira.springsource.org/browse/SPR-7963
答案 1 :(得分:0)
尝试以此格式发送数据。
<强>句: “A; B,C; d”强> 请注意,在这种情况下,您的分隔符是;不,所以你发送了一个包含
列表的字符串@RequestMapping(value = "somemethod", method = RequestMethod.POST)
public ModelAndView exportSomething(@RequestParam("sentences") String sentences) {
String[] sentenceArray = sentences.split(";");
for(String tempString:sentenceArray){
// perform what operation you want to perform
}
}
在这种情况下,您将得到一个大小为3而不是四的数组。
您的方法无效的原因可能是因为您使用了逗号,它是数组的默认分隔符。