One, MIME type
MIME type format: Type/subtype (;p arameter)?
- Type: The main type, any string, such as text, if the * number represents all
- Subtype: Sub-type, arbitrary string, such as HTML, if the * number represents all
- Parameter: Optional parameters, such as the Q parameter of the Accept request header, Content-type charset parameter
Several common MIME types are:
- Html:text/html
- form data: application/x-www-form-urlencoded
- JSON data: Application/json
- GIF Image: Image/gif
All MIME types supported by the server are specified in the Tomcat home directory under Conf/web.xml
Ii. Producer and Consumer models
1, Content-type and accept
i) Content-type: Content type, which is the MIME type of the request/response content area data, such as:
content-type:application/x-www-form-urlencoded Content-type:application/json;charset=utf-8
II) Accept: To specify the MIME type acceptable to the browser, the server should produce data of the specified MIME type according to the Accept request header, with multiple types separated by commas, such as:
accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
2. Producers and consumers
Request phase: The client is the producer (the request content area data for the production Content-type media type), and the server is the consumer (Request content area data for the Content-type media type produced by the consumer client)
Response phase: The server is the producer (the response body data specified by the production client request header parameter), and the client is the consumer (the consumer server produces the response body data according to the Accept request header)
From the perspective of the server, the functional approach is the consumer of the request (the Content-type header designation of the request packet), the producer of the response (the Accept header designation of the request packet), which abstracts the producer and consumer model
The @RequestMapping provides two properties, consumes, produces, for implementing the model, using the following example:
// equivalent to: headers = {"content-type=application/x-www-form-urlencoded"}@RequestMapping (value = "/head2", consumes = {"application/x-www-form-urlencoded"}) @ResponseBody public String testHeader2 () { return "TestHeader2";} // equivalent to: headers = {"Accept=application/json;charset=utf-8"}@RequestMapping (value = "/head3", produces = {" Application/json;charset=utf-8 "}) @ResponseBody public String TestHeader3 () { return "TestHeader3";}
3, the producer and the consumer to narrow is the cover rather than the inheritance
= "text/html")publicclass TestController4 { = "/narrow", consumes = " application/x-www-form-urlencoded ") @ResponseBody public String testnarrow () { return "Narrow"; }}
When requested, Content-type is "text/html" 404, for "application/x-www-form-urlencoded" to respond normally
Other properties of the @RequestMapping are inheritance relationships, such as headers, params, and so on
Reference:
Producer, consumer request limit--Follow the TAO study Springmvc
Introduction to Spring MVC usage (vii)--Annotated Controller (III)