我有一个非常奇怪的问题
我的控制器读取String[] paramDescriptions
除非在ajax中发送的大小为1,否则读取效果很好。如果大小为1,我没有得到任何值。
var paramDescriptions = [];
var paramDescriptionInputs = $('input[name="paramDescriptions"]');
$(paramDescriptionInputs).each(function(index, val) {
paramDescriptions.push($(val).val());
});
console.log(paramDescriptions);
var formData = new FormData();
formData.append("paramDescriptions", paramDescriptions);

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1> 2 values or more works </h1>
<input type="text" class="form-control" placeholder="Insert the description for EXPECTED_RATE_VALUE" name="paramDescriptions" id="paramName1">
<input type="text" class="form-control" placeholder="Insert the description for EXPECTED_RATE_VALUE" name="paramDescriptions" id="paramName2">
<h1> 1 doesn't </h1>
<input type="text" class="form-control" placeholder="Insert the description for EXPECTED_RATE_VALUE" name="paramDescriptions" id="paramName3">
&#13;
后端
@RequestMapping(value = "/upload/testCase" , method = RequestMethod.POST)
public @ResponseBody String uploadTestCase(@RequestParam(value = "paramDescriptions", required = false) String[] paramDescriptions) {
System.out.println(paramDescriptions);
}