봄 화면 음악(5)쓰기 응답

1331 단어 spring mvc
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);
}

좋은 웹페이지 즐겨찾기