@ResponseBody
註解可被應用於方法上,標誌該方法的返回值(更正,原文是return type,看起來應該是返回值)應該被直接寫回到HTTP響應體中去(而不會被被放置到Model中或被解釋爲一個視圖名)。舉個例子:
package com.imooc.mvcdemo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/hello")
public class HelloMvcController {
@RequestMapping("/mvc")
@ResponseBody
public String helloMvc() {
return "home";
}
}
如果這樣執行的話,就是在屏幕直接輸出hello。
如果將@RequestMapping去掉就是返回一個jsp頁面