spring mvc(五)Writing Response
Response Body
http://localhost:8080/spring_mvc_test/response/annotation
@RequestMapping(value="/response/annotation", method=RequestMethod.GET)public @ResponseBody String responseBody() {String message = "The String ResponseBody";return message;}
@RequestMapping(value="/response/entity/status", method=RequestMethod.GET)public ResponseEntity<String> responseEntityStatusCode() {return new ResponseEntity<String>("the String ResponseBody with custom status code (403 Forbidden)",HttpStatus.FORBIDDEN);}
@RequestMapping(value="/response/entity/headers", method=RequestMethod.GET)public ReponseEntity<String> responseEntityCustomHeaders() {HttpHeaders headers = new HttpHeaders();headers.setContentType(MediaType.TEXT_PLAIN);return new ReponseEntity<String>("The String ResponseBody with custom header Content-Type=test/plain",headers, HttpStatus.OK);}