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<String,String> 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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…