测试开发进阶——spring boot——MVC——get访问——接收前端传递的数组

时间:2021-07-31
本文章向大家介绍测试开发进阶——spring boot——MVC——get访问——接收前端传递的数组,主要包括测试开发进阶——spring boot——MVC——get访问——接收前端传递的数组使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

控制器:

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中,前端往后端除了可以传递一些单值外,也可以传递数组。

传递数据部分没有太多规则可言,在后台控制器部分,定义数组形式接收数据,前端传递时,将一组数据用英文的逗号“,”隔开就可以了。

原文地址:https://www.cnblogs.com/xiaobaibailongma/p/15084846.html