Character encoding of controller in spring MVC
When building web applications using the spring MVC framework, clients often request data in string, integer, JSON and other formats. They usually use the @ ResponseBody annotation to make the controller respond to the corresponding data instead of rendering a page. If the requested string is not in English format, it is often displayed in garbled code on the client. The reason is that the default character type of spring's stringhttpmessageconverter is iso8895-1 'Western European language', and Chinese characters need to be specified separately.
Several solutions are summarized here:
1. Use httpserveretresponse to set contenttype property without @ ResponseBody annotation
2. Return the response entity object and set the contenttype, for example:
3. Use the produces attribute:
@RequestMapping
Parameter binding (@ requestparam, @ requestbody, @ requestheader, @ pathvariable)
Requestmapping is an annotation used to handle request address mapping, which can be used on classes or methods. Used on a class to indicate that all methods in the class that respond to requests take this address as the parent path.
The requestmapping annotation has six properties.
1、value, method;
Value: specify the actual address of the request. The specified address can be URI template mode (described later);
Method: Specifies the method type of the request, such as get, post, put, delete, etc;
2、consumes,produces;
Consumers: specify the submitted content type for processing the request, such as application / JSON, text / HTML;
Products: Specifies the content type to be returned. It is returned only if the (accept) type in the request header contains the specified type;
3、params,headers;
Params: Specifies that the request must contain some parameter values of yes before it can be processed by this method.
Headers: Specifies that the request must contain some specified header values in order for the method to process the request.
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.