@RestController介绍
我们在Controller中使用 @RestController 注解,该注解是spring 4.0引入的。查看源码可知其包含了 @Controller 和 @ResponseBody 注解。
我们可以理解为 @Controller的增强版。专门为响应内容式的 Controller 而设计的,可以直接响应对象为JSON。而 @Controller 用来响应页面
@Controller实现
创建PageController
package cn.wuyang.springboot.controller;
import java.util.Date;
import java.util.Map;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping(value="/page")
public class PageController {
// 从 application.properties 中读取配置,如取不到默认值为Hello Shanhy
@Value("${application.hello}")
private String hello = "Hello wuyang";
/**
* 默认页<br/>
*