---
title: "spring mvc（五）Writing Response"
author: "mistbow"
date: "2011-12-06T10:23:44Z"
tags: []
categories: ["编程语言"]
slug: "spring-mvc-writing-response"
draft: false
lastmod: "2011-12-06T10:23:44Z"
id: 1293210
url: "https://mistbow.iteye.com/blog/1293210"
---

\[color=blue]Response Body\[/color] http://localhost:8080/spring\_mvc\_test/response/annotation \[code="java"]@RequestMapping(value="/response/annotation", method=RequestMethod.GET) public @ResponseBody String responseBody() { String message = "The String ResponseBody"; return message; }\[/code] \[color=blue]ResponseEntity(custom status) The String ReponseBody with custom status code(403 Forbidden)\[/color] \[code="java"]@RequestMapping(value="/response/entity/status", method=RequestMethod.GET) public ResponseEntity responseEntityStatusCode() { return new ResponseEntity("the String ResponseBody with custom status code (403 Forbidden)", HttpStatus.FORBIDDEN); }\[/code] \[color=blue]ResponseEntity(custom headers) The String ReponseBody with custom header Content-Type=test/plain\[/color] \[code="java"]@RequestMapping(value="/response/entity/headers", method=RequestMethod.GET) public ReponseEntity responseEntityCustomHeaders() { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.TEXT\_PLAIN); return new ReponseEntity("The String ResponseBody with custom header Content-Type=test/plain", headers, HttpStatus.OK); }\[/code]