@ResponseBody

@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頁面 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章