首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

spring mvc(5)Writing Response

2012-11-10 
spring mvc(五)Writing ResponseResponse Bodyhttp://localhost:8080/spring_mvc_test/response/annotatio

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;}


ResponseEntity(custom status)
The String ReponseBody with custom status code(403 Forbidden)
@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);}

ResponseEntity(custom headers)
The String ReponseBody with custom header Content-Type=test/plain
@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);}

热点排行