Appearance
直接点
打开localhost:8080,默认显示Spring Boot的报错页,由页面内容可以看出报错为 404 ,访问其他地址也都会是这个页面,此时的 web 服务中并没有任何可访问资源,因为我们并没有在项目中增加任何一行代码,没有接口,也没有页面。
自行实现一个 Controller 来测试一下 Spring Boot 如何处理 web 请求,在根目录(启动类的同级目录,不是 src 目录)下新建 controller 包,之后在包里新建一个 Controller 类,编码如下
: package ltd.newbee.mall.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller public class IdeaController {
@GetMapping("/info")
@ResponseBody
public String getInfoFromIdea() {
return "this is a spring boot project from idea";
} } 重新启动项目并在浏览器中输入地址http://localhost:8080/info,可以看到已经没有错误页面,而是 Controller 中的正确返回,咱们的第一个 Spring Boot 项目实例就完成了!
