@ResponseBody
@ResponseBody 将内容或对象作为 HTTP响应正文返回,并调用适合HttpMessageConverter的Adapter转换对象,写入输出流。
@RequestMapping("/annotation")
public @ResponseBody String responseBody() {
return "The String ResponseBody";
}
设置响应编码
@RequestMapping(value="/charset/produce", produces="text/plain;charset=UTF-8")
public @ResponseBody String responseProducesConditionCharset() {
return "\u3053\u3093\u306b\u3061\u306f\u4e16\u754c\uff01 (\"Hello world!\" in Japanese)";
}
网友评论