How do I pass an array to a Spring controller method with jquery ajax

后端 未结 3 1551
孤城傲影
孤城傲影 2021-02-13 18:44

Here\'s my ajax call:

 $.ajax({
     type: \'GET\',
     url: contextPath + \'/test/location\',
     data: {\'objectValues\': object.objectValues },
     datatyp         


        
3条回答
  •  遇见更好的自我
    2021-02-13 19:19

    Try changing your RequestParam annotation value to this:

    @RequestParam(value="objectValues[]", required=false)
    

    If this solves the problem, then it is due to a parameter naming incompatibility between Spring and jQuery, where jQuery wants to put square brackets in to indicate that a parameter is an array (I think PHP likes this too), but where Spring doesn't care. To see the reverse try setting the "data" parameter of the ajax request to the string: 'objectValues=1234567890&objectValues=0987654321'

提交回复
热议问题