@RestController
Spring4之後新加入的註解,原來返回JSON需要@ResponseBody和@Controller配合。
即@RestController是@ResponseBody和@Controller的組合註解
@RestController = @Controller + @ResponseBody;
@RestController
public class TestController {
@RequestMapping(value="/hello", method= RequestMethod.GET)
public String hello(){
return "hello";
}
}
與下面的一樣:
@Controller
@ResponseBody
public class TestController {
@RequestMapping(value="/hello", method= RequestMethod.GET)
public String hello(){
return "hello";
}
}