接收数组

页面请求:

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

你可能感兴趣的:(接收数组)