关于Ajax请求传递数组参数和多参数传递的解决办法

Ajax发送请求传递多个参数时,我们可以通过表单序列化 $("form").serialize()

但是再加一个数组参数该传递就不行了。经过测试最终找到解决办法!


  前端测试代码  test.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>





测试


	
用户名:
密码:
超级管理员:  管理员:

Controller控制层代码

package com.liuchao.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.liuchao.projo.JResult;
import com.liuchao.service.UserRoleService;

@Controller
@RequestMapping("/user")
public class UserRoleController {

	@Autowired
	private UserRoleService userRoleService;

	@RequestMapping("/addUser2")
	@ResponseBody
	public JResult addUser2(String userName,String pwd,String [] roleList) {//此处必须使用数组接收,名称和前端Ajax的参数名一致。
		System.out.println(userName+pwd+roleList.toString());
		return userRoleService.addUser2(userName,pwd,roleList);
	}
}

如果该方法解决不了,另一种可以解答:https://blog.csdn.net/qq_40943363/article/details/82496762

你可能感兴趣的:(关于Ajax请求传递数组参数和多参数传递的解决办法)