3. New Features and Enhancements in Spring Framework 3.1

This is a list of new features for Spring Framework 3.1. A number of features do not have dedicated reference documentation but do have complete Javadoc. In such cases, fully-qualified class names are given. See also Appendix C, Migrating to Spring Framework 3.1



3.14 "consumes" and "produces" conditions in @RequestMapping

Improved support for specifying media types consumed by a method through the 'Content-Type' header as well as for producible types specified through the 'Accept'header. See the section called “Consumable Media Types” and the section called “Producible Media Types”



Consumable Media Types

You can narrow the primary mapping by specifying a list of consumable media types. The request will be matched only if the Content-Type request header matches the specified media type. For example:

@Controller
@RequestMapping(value = "/pets", method = RequestMethod.POST, consumes="application/json")
public void addPet(@RequestBody Pet pet, Model model) {
    // implementation omitted
}

Consumable media type expressions can also be negated as in !text/plain to match to all requests other than those with Content-Type of text/plain.

[Tip]Tip

The consumes condition is supported on the type and on the method level. Unlike most other conditions, when used at the type level, method-level consumable types override rather than extend type-level consumable types.

Producible Media Types

You can narrow the primary mapping by specifying a list of producible media types. The request will be matched only if the Accept request header matches one of these values. Furthermore, use of the produces condition ensures the actual content type used to generate the response respects the media types specified in the produces condition. For example:

@Controller
@RequestMapping(value = "/pets/{petId}", method = RequestMethod.GET, produces="application/json")
@ResponseBody
public Pet getPet(@PathVariable String petId, Model model) {
    // implementation omitted
}

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.

[Tip]Tip

The produces condition is supported on the type and on the method level. Unlike most other conditions, when used at the type level, method-level producible types override rather than extend type-level producible types.

출처 - http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/new-in-3.1.html

http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/mvc.html#mvc-ann-requestmapping-produces








서버 side 에서 

Producible Media Types은 GET Method로 요청을 받아 서버가 응답(생성)해 줄 때

Consumable Media Types POST Method로 데이터를 받아 서버가 처리(소비)해 줄 때





 












Posted by linuxism

댓글을 달아 주세요