ssm中 controller 如何接收ajax传来的string 数组?

图片说明
以上是我前端获取到的数值
@RequestMapping("deleteByInfoPanelIds")
@ResponseBody
public JsonResult deleteByInfoPanelIds(@Param("deviceId") String[] s){
System.out.println(s);
//infoPanelService.deleteInfoPanelByIds(list);
return new JsonResult();
}

    以上是我controller 的写法。各种方法都试过了,目前这么写s的值为null。。悬赏求解,在线等

应该接受不了数组吧,先拼字符串后台接收到再解开比较靠谱一点。

按理不应该是通过ajax把后台的数据传输到前端的页面吗?

 public JsonResult deleteByInfoPanelIds(@Param("deviceId") String s){
 //……
}
直接用Strinng接受,然后再在后台解析成JSON

首先 ajax里面可以直接传入参数
$.ajax({
type:'POST',
url:'sendPwd?fid=${sendPwd.funcNo}',
data:{userId:userId,merchantId:merchantId},
async:false,
cache:false,
dataType:'json',
success: function(msg){

},
error:function(XMLHttpRequest, textStatus, errorThrown){
}
像这种,直接在url后面带上你要的参数

                    然后你的requestmapping里的url
                    要加/
                    @RequestMapping("/deleteByInfoPanelIds")

然后还可以通过后台的@param的方法或者requet.getparamer("");的方法获取前台的数据

楼上的方法可以尝试一下,在ajax传值过去的时候先将值拼成字符串,用逗号分隔成数组,再进行循环操作,接数组还没有操作过

for ( var i = 0; i < rows.length; i++) {
                        ids.push(rows[i].id);
                    }
 $.ajax({
                        url : url,
                        type : 'post',
                        data : {
                            ids : ids.join(',')
                        },
                        cache : false,
                        success : function(data) {
 前台
         $.ajax({
            url: "${ctx}/goodsorder/createOrderItem",
            type: "post",
            data: {
                "arrCarItems": arrCarItems,   //这是数组
                "userId":${sessionScope.user.userId}
           },
                            traditional: true         //加上这个试试
 //……


后台


    @ResponseBody
    @RequestMapping(value = "/createOrderItem")
    public BaseHelper createOrderItem(Integer[] arrCarItems, Integer userId) {
        //……
        }


这上面的代码时可行的!

建议使用字符串传参,后台收到后分割成数组。