The class is flagged as a @RestController, meaning it’s ready for use by Spring MVC to handle web requests.
@RestController combines@Controller and@ResponseBody, two annotations that results in web requests returning data rather than a view.thus,下面Spring程序的代码片段可以直接return回数据,不然需要的是html格式的view。
@RestController
public class HelloController {
@RequestMapping("/")
public String index() {
return "Greetings from Spring Boot!"; //由于是@RestController,因此直接返回数据,而不是view
}
}
参考:
1.https://spring.io/guides/gs/spring-boot/