Home > Back-end >  Ask for help, SSM4.1.7 ResponseBody in 406
Ask for help, SSM4.1.7 ResponseBody in 406

Time:10-07

Afternoon in writing the SSMdemo found in ajax and control is used when the json data exchange to 406, the controller can receive the json message from the front end controller back in 406,
For SpringMVC version 4.1.7
Jackson - core, Jackson - databind, Jackson - annotations version 2.9.8
This is the MVC. Part of the XML configuration
 & lt; MVC: annotation - driven/& gt; 

(1) to join handling of static resources: js, GIF, PNG
(2) to allow the use of "/" do whole map

- & gt;



This is a function of the controller to be tested in the
/* */test 
@ RequestMapping (value="https://bbs.csdn.net/detail/dto", method=RequestMethod. POST,
Produces={" application/json; Charset=utf-8 "})
@ ResponseBody
Private Result TestDto (@ RequestBody TestExecution execution) {
System. The out. Println (execution. GetBooks ());
AppointExecution execution1=new AppointExecution (execution. GetAppointment () getBookId (), AppointStateEnum. INNER_ERROR);

Return new Result (execution1, true);
}

This is the place where the JSP file using ajax
 

Var dto={};
Dtos. Appointment={
BookId: 250,
StudentId: 100,
AppointTime: null,
Book: {bookId: 5, name: "666", number: 5}
};
Dtos. Books=[{bookId: 5, name: "666", number: 5}, {bookId: 5, name: "678", number: 5}, {bookId: 5, name: "678", number: 5}].
$. Ajax ({
Type: "POST",
Url: "../detail/dto,
"ContentType: "application/json; Charset=utf-8,
"Data: JSON. Stringify (dto),//invoke ajax, data attribute must writes, must
Success: the function (data, status) {
Alert (data. The data. BookId);
},
Error: function (XMLHttpRequest, textStatus errorThrown) {
Alert (textStatus);
}
}); </script>

Browser f12 view

CodePudding user response:

Have to solve, replaced fastjson can
  • Related