后端RequestBody接收map,前端怎么传值
时间: 2023-08-24 15:13:02 浏览: 192
在前端,如果后端使用@RequestBody接收Map参数,可以使用ajax的data属性将参数以JSON字符串的形式传递给后端。在你提供的代码中,可以将jsonObj转换成JSON字符串,并将其作为data属性的值传递给后端。具体代码如下:
```javascript
var jsonObj = { "mrcNo":mrcNo, "ordId":ordId };
var paramerters = JSON.stringify(jsonObj);
$.ajax({
type: 'post',
url: "getSmsCd",
contentType: 'application/json;charset=UTF-8',
dataType: 'json',
data: paramerters,
success: function(data){
if(data != null){
document.getElementById("smsCd").value = data.smsVerifCd;
}else{
alert("XXX失败");
}
},
error: function(){
alert("网络异常!请稍后重试!");
}
});
```
这样,后端就可以通过@RequestBody注解接收到前端传递的Map参数。
#### 引用[.reference_title]
- *1* [前端传值,后端使用Map接受](https://blog.csdn.net/administratop/article/details/126667702)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [后台@RequestBody接收参数,前台js该如何在ajax中传值?](https://blog.csdn.net/gongjin28_csdn/article/details/107403758)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文