控制器:
package com.awaimai.web;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;
@RestController
public class kzq
{
@RequestMapping("/param/requestarray")
@ResponseBody
public Map<String, Object> requestArray(String[] names, int[] ages, double[] scores)
{
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("name", names);
paramMap.put("age", ages);
paramMap.put("score", scores);
return paramMap;
}
}
web访问:
springMVC中,前端往后端除了可以传递一些单值外,也可以传递数组。
传递数据部分没有太多规则可言,在后台控制器部分,定义数组形式接收数据,前端传递时,将一组数据用英文的逗号“,”隔开就可以了。