Browse Source

Add @RequestMapping produces documentation about charset

Issue: SPR-13600
pull/909/head
Sebastien Deleuze 10 years ago
parent
commit
62cd6ad526
  1. 5
      spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMapping.java
  2. 12
      src/asciidoc/web-mvc.adoc

5
spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMapping.java

@ -414,8 +414,11 @@ public @interface RequestMapping { @@ -414,8 +414,11 @@ public @interface RequestMapping {
* <pre class="code">
* produces = "text/plain"
* produces = {"text/plain", "application/*"}
* produces = "application/json; charset=UTF-8"
* </pre>
* Expressions can be negated by using the "!" operator, as in "!text/plain", which matches
* <p>It affects the actual content type written, for example to produce a JSON response
* with UTF-8 encoding, {@code "application/json; charset=UTF-8"} should be used.
* <p>Expressions can be negated by using the "!" operator, as in "!text/plain", which matches
* all requests with a {@code Accept} other than "text/plain".
* <p><b>Supported at the type level as well as at the method level!</b>
* When used at the type level, all method-level mappings override

12
src/asciidoc/web-mvc.adoc

@ -1028,13 +1028,21 @@ condition. For example: @@ -1028,13 +1028,21 @@ condition. For example:
[subs="verbatim,quotes"]
----
@Controller
@RequestMapping(path = "/pets/{petId}", method = RequestMethod.GET, **produces="application/json"**)
@RequestMapping(path = "/pets/{petId}", method = RequestMethod.GET, **produces="application/json; charset=UTF-8"**)
@ResponseBody
public Pet getPet(@PathVariable String petId, Model model) {
// implementation omitted
}
----
[NOTE]
====
Be aware that the media type specified in the __produces__ condition can also optionally
specify a character set. For example, in the code snippet above we specify the same media
type than the default one configured in `MappingJackson2HttpMessageConverter`, including
the `UTF-8` charset.
====
Just like with __consumes__, producible media type expressions can be negated as in
__!text/plain__ to match to all requests other than those with an __Accept__ header
value of __text/plain__.
@ -3847,7 +3855,7 @@ When writing error information, the status code and the error message set on the @@ -3847,7 +3855,7 @@ When writing error information, the status code and the error message set on the
@Controller
public class ErrorController {
@RequestMapping(path="/error", produces="application/json")
@RequestMapping(path="/error", produces="application/json; charset=UTF-8")
@ResponseBody
public Map<String, Object> handle(HttpServletRequest request) {

Loading…
Cancel
Save