1. Introduction to Ajax
Asynchronous JavaScript and XML asynchronous JavaScript and XML
Ajax is a technique used to improve the user experience, with the features of asynchronously processing and refreshing part of a page's content
Ajax technology requires both client-side JavaScript processing and server processing in the application.
When using AJAX technology, the following work is required
Write JavaScript programs to send AJAX requests
Write server processing, return processing results (common JSON format)
Write JavaScript programs, get server results, refresh some pages
2. Spring Support for Ajax
To facilitate the acceptance and processing of AJAX requests, Spring MVC provides support for JSON responses that can easily be automatically turned into JSON format strings for client-side JavaScript to return
In Springmvc, JSON-related annotations are @responsebody
3. @ResponseBody Application
@ResponseBody annotations are mainly used before the Controller component processing methods, the following methods are used:
The Jackson Development Kit was introduced, followed by Jackson-annotations-2.4.1.jar, Jackson-core-2.4.1.jar, Jackson-databind-2.4.1.jar
Define <MVC:ANNOTATION-DRIVEN/> in the spring configuration file, turn on support for @responsebody apps
Define @responsebody annotations before controller processing methods
@ResponseBody applications
1. Use @responsebody to return an instance of a single value as follows:
Spring and Ajax