前后端——json的传值与接收(springMvc)

data:JSON.stringify(excelData),

type : “post”,

dataType: “json”,

contentType: “application/json; charset=utf-8”,//此处不能省略

success : function(data) {

alert(“success”)

},

error:function(){

alert(“fail”)

}

});

})

后端:

@ResponseBody

@RequestMapping(value = “/excel”, method = RequestMethod.POST)

public Msg excel(@RequestBody String param) throws Exception {

System.out.println(“param=”+param);

JSONObject jo=new JSONObject();

List parseArray = jo.parseArray(param, Map.class);

System.out.println(“parseArray=”+parseArray);

for (Map map:parseArray) {

System.out.println(“map=”+map);

}

return null;

}

以上就是传值与接收值的具体情况,当然也可以封装一个bean对象,直接转为bean也行

下面继续拓展一个springMvc的知识,如果前端传值是通过这种方式:

$(“#excelOutput”).click(function(){

console.log(“传出的数据=”+JSON.stringify(excelData))

$.ajax({

url : “${App_Path}/excel/”+result,

data:JSON.stringify(excelData),

type : “post”,

dataType: “json”,

contentType: “application/json; charset=utf-8”,//此处不能省略

success : function(data) {

alert(“success”)

},

error:function(){

alert(“fail”)

}

});

})

上面传了两个值,一个是result,一个是excelData,看后端怎么处理:

@ResponseBody

@RequestMapping(value = “/excel/{result}”, method = RequestMethod.POST)

public Msg excel(@RequestBody String param,@PathVariable String result) throws Exception{

System.out.println(“param=”+param);

System.out.println(“result=”+result);//result就是url : “${App_Path}/excel/”+result中的result

最后总结我的面试经验

2021年的金三银四一眨眼就到了,对于很多人来说是跳槽的好机会,大厂面试远没有我们想的那么困难,摆好心态,做好准备,你也可以的。

另外,面试中遇到不会的问题不妨尝试讲讲自己的思路,因为有些问题不是考察我们的编程能力,而是逻辑思维表达能力;最后平时要进行自我分析与评价,做好职业规划,不断摸索,提高自己的编程能力和抽象思维能力。

BAT面试经验

实战系列:Spring全家桶+Redis等

其他相关的电子书:源码+调优

面试真题:


书:源码+调优**

[外链图片转存中…(img-46OXs4Ce-1719190104139)]

面试真题:

[外链图片转存中…(img-w37gJykD-1719190104140)]

[外链图片转存中…(img-2huMKcKu-1719190104140)]

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值