利用Idea构建SpringBoot项目
系统环境
- 编辑器:Idea2018.1
- 操作系统:win7
- maven:1.8.0_171
步骤
- 打开Idea:File->New->Project->Spring Initializr,直接点击下一步
- 跳出的界面设置Group、Artifact、Version、Type(这里我使用的默认的Maven Project),下一步
- 跳出的选项Dependencies中选择Web,并在右侧勾选Web,点击下一步
- 确认名称和路径,直接点击Finish
- 启动后目录如下:
这样我们就算成功创建了SpringBoot项目,但是想要看到项目跑起来的效果,可以再DemoApplication.java所在目录下新建controller/DemoController.java测试
package com.example.demo.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
/**
* 第一个SpringBoot接口测试
*/
@RestController
public class DemoController {
/**
* 输出HelloWorld!
* @return String "HelloWorld!"
*/
@RequestMapping(value = "/demo", method = RequestMethod.GET)
public String helloWorld(){
return "HelloWorld!";
}
}
运行项目,当看到
Completed initialization in xxx ms
时,打开Tool->Http Client->Test RESTful Web Service
请求GET:localhost:8080/demo
查看Response返回了我们需要的结果: