项目用到的环境:web
选择类型为Spring Initializer.spring
接着下一步, 选择web.json
再下一步, 选择项目的路径, 点击完成app
新建成的项目的文件目录结构以下图:spring-boot
pom.xml以下所示:测试
<dependencies>
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies>
其中, spring-boot-starter-web是支持web的模块, spring-boot-starter-test是支持测试的模块.spa
添加一个HelloWorldController以下:code
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloWorldController { @RequestMapping("/") public String index(){ return "Hello World"; } }
@RestController表示里边的方法都以json格式输出, 无需再添加额外的json配置.xml
点击Shift + F10 或者直接点击运行, 待项目启动成功后, 访问http://localhost:8080ci
如图即表示第一个spring boot项目启动成功.