(1)创建spring initializr工程
通过idea工具创建工程时,不再选择maven了而是选择spring initializr。然后去勾选相关依赖。
step1:新建module,选择spring initializr,然后下一步(如果默认网址不行可以换https://start.aliyun.com/)
step2:填写项目相关信息
step3:勾选需要的依赖
step4:完成,工程的目录结构如下
编写程序:
(1)编写HelloController
在工程的src目录下创建com.qf.controller.HelloController
@RestController
public class HelloController {
/**
* 请求 /hello 输出hello springboot!
* @return
*/
@RequestMapping(value = "/hello")
public String hello(){
return "hello springboot!";
}
}
2.测试(在springb里有启动类每次更改 都要运行即XXXXapplication)
访问:http://localhost:8080/hello
3.运行结果
小结:
-
使用SpringBoot,我们只用关注业务逻辑,而不用关注业务
-
启动SpringBoot工程:直接启动启动类的主方法即可(默认集成了tomcat:8080)