springmvc ajax map,ajax - Passing a Map<String,String> to a springMVC controller - Stack Overflow

博主在尝试使用Ajax向SpringMVC控制器发送HashMap或其他Map实现时遇到问题,错误信息提示无法将String类型转换为Map。在Ajax调用中,博主创建了一个包含键值对的对象并尝试发送,而在控制器端接收到的参数无法正确转换。问题可能出在数据类型转换上,需要找到适配的编辑器或转换策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I am trying to send a HashMap or any other Map implementation from ajax to a Spring MVC controller

Here's the detail of how I do it :

the Ajax call is as follow

var tags = {};

tags["foo"] = "bar";

tags["whee"] = "whizzz";

$.post("doTestMap.do", {"tags" : tags }, function(data, textStatus, jqXHR) {

if (textStatus == 'success') {

//handle success

console.log("doTest returned " + data);

} else {

console.err("doTest returned " + data);

}

});

then on the controller side I have :

@RequestMapping(value="/publisher/doTestMap.do", method=RequestMethod.POST)

public @ResponseBody String doTestMap(@RequestParam(value = "tags", defaultValue = "") HashMap tags, HttpServletRequest request) { //

System.out.println(tags);

return "cool";

}

Unfortunately I systematically get

org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'java.lang.String' to required type 'java.util.Map'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.util.Map]: no matching editors or conversion strategy found

What am I doing wrong ?

Thank you.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值