Address mapping of @RequestMapping usage details

Introduction:
Some time ago, the RESTful mode was used in the project to develop the program, but when the data was submitted in the POST and PUT modes, it was found that the server side could not accept the submitted data (the server-side parameter binding did not add any annotations), and checked the submission method. It is application/json, and the data sent by the server through request.getReader() does exist in the data submitted by the browser. In order to find out the reason, I studied the parameter binding (@RequestParam, @RequestBody, @RequestHeader, @PathVariable), and also looked at the relevant content of HttpMessageConverter, and summed it up here

. Introduction
: @RequestMapping

RequestMapping is a Annotation to handle request address mapping, which can be used on classes or methods. Used on a class, indicating that all methods in the class that respond to requests use this address as the parent path.

The RequestMapping annotation has six attributes. Below we divide it into three categories to explain

1. value, method
value: Specify the actual address of the request, and the specified address can be in URI Template mode (will be explained later);

method: Specify the method of the request Type, GET, POST, PUT, DELETE

2, consumes, produces
consumes: Specify the submitted content type (Content-Type) for processing requests, such as application/json, text/html;

produces: Specify the returned content type, only when the request request The specified type is returned only if the (Accept) type in the header contains the specified type;


3. params, headers
params: Specifies that the request must contain certain parameter values ​​for this method to process.

headers: The specified request must contain certain specified header values ​​in order for this method to process the request

http://blog.csdn.net/walkerjong/article/details/7994326

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326374023&siteId=291194637