一:准备环境
1.JDK环境:JDK1.8
开发环境:IDEA2018.3
二:创建IDEA项目工程
三:HelloWorld实例
-
目录结构:
-
编写controllor代码
package com.controller; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @EnableAutoConfiguration public class helloController { @RequestMapping("/hello") private String hello(){ return "Hello World!"; } }
-
注意!!!
DemoApplication 一定要放在包的最外层!!!否则出现以下错误!!!
四:项目启动
两种方式:
- application启动
-
IDEA工具栏启动
五:测试helloworld
打开浏览器输入: http://localhost:8080/hello