spring mvc 3中的consumes
spring mvc 3中的consumes,其实就是当请求的HTTP 头是何种格式的时候,进行应对,
比如请求为application/xml,application/json,下面看个例子:
@Controllerpublic class ExampleController { @RequestMapping(value = "/test", method = RequestMethod.POST, consumes = "application/xml") public ResponseEntity<String> processXml( @RequestBody String requestBody){ return new ResponseEntity<String>( "Handled application/xml request. Request body was: " + requestBody, new HttpHeaders(), HttpStatus.OK); } @RequestMapping(value = "/test", method = RequestMethod.POST, consumes = "application/json") public ResponseEntity<String> processJson( @RequestBody String requestBody){ return new ResponseEntity<String>( "Handled application/json request. Request body was: " + requestBody, new HttpHeaders(), HttpStatus.OK); } }