接收数组

页面请求:

function send(){
    var id = 18;
    var ids = [1, 2, 3, 4];
    $.ajax({
        url: 'http://localhost:8080/ajax/test2',
        type: 'post',
        //contentType: 'application/json;charset=utf-8', //使用默认表单的方式提交
        data: {"id": id, "ids": ids.toString()}, //ids.toString() = '1,2,3,4'
        success: function(data){
            console.log(data);
            console.log(JSON.stringify(data));
        }
    });
}

Controller处理器

package com.example.demo.web;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/ajax")
public class AjaxController {

    @RequestMapping("test2")
    @ResponseBody
    public String test2(Integer id, Integer[] ids) {
        System.out.println(id);
        for(int i=0; i<ids.length; i++) {
            System.out.println(ids[i]);
        }
        return null;
    }
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容