से एक साधारण नक्शा संरचना लौट रहा है मैं वसंत एमवीसी 4 का उपयोग कर रहा हूं और मेरे नियंत्रक से jsp फ़ाइल तक - एक सरल map
AJAX पर वापस लौटने की कोशिश कर रहा हूं।वसंत एमवीसी नियंत्रक से AJAX
नियंत्रक:
jsp फ़ाइल से@RequestMapping(value = "/ajaxtest", method = RequestMethod.GET)
public @ResponseBody
Map<String, String> myTest() {
System.out.println("------------------------------------test");
Map<String,String> myMap = new HashMap<String, String>();
myMap.put("a", "1");
myMap.put("b", "2");
return myMap;
}
अजाक्स:
function testAjax() {
$.ajax({
url : '../../ajaxtest.html',
dataType: "json",
contentType: "application/json;charset=utf-8",
success : function(data) {
alert("1");
alert(data);
}
});
}
लेकिन मैं किसी भी चेतावनी लेकिन सिर्फ त्रुटि HTTP/1.1 406 Not Acceptable
नहीं मिल रहा है।
हालांकि, एक साधारण स्ट्रिंग को वापस करने के लिए कोड को बदलना ठीक काम करता है। नियंत्रक:
@RequestMapping(value = "/ajaxtest", method = RequestMethod.GET)
public @ResponseBody
String myTest() {
System.out.println("------------------------------------test");
return "hello";
}
अजाक्स:
function testAjax() {
$.ajax({
url : '../../ajaxtest.html',
success : function(data) {
alert("1");
alert(data);
}
});
}
ajax से 1
और hello
की सूचना देने वाले के रूप में उम्मीद।
dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.5.1</version>
</dependency>
Am मैं कुछ कमी:
मैं (pom.xml से) के रूप में उम्मीद जैक्सन जार फ़ाइलें जोड़ी? मैं बस एक साधारण मानचित्रण संरचना (या भविष्य में अन्य वर्ग संरचना) वापस करना चाहता हूं।
अद्यतन: अग्रिम में Resolving exception from handler [null]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
धन्यवाद: वसंत कंसोल से (यकीन है कि यह संबंधित नहीं है)! माइक
जोड़ा गया '@RequestMapping (value = "/ ajaxtest", method = RequestMethod.GET, उपभोग = "एप्लिकेशन/जेसन", = = "एप्लिकेशन/जेसन"} उत्पन्न करता है) लेकिन समस्या को हल नहीं किया ... – Mike