springBoot02_案例细节、使用向导快速创建springBoot项目、重新导入

案例细节

springBoot02_案例细节、使用向导快速创建springBoot项目、重新导入

场景启动器

springBoot02_案例细节、使用向导快速创建springBoot项目、重新导入
里边有各种场景启动器,用到哪个就是导入依赖
springBoot02_案例细节、使用向导快速创建springBoot项目、重新导入

主程序

springBoot02_案例细节、使用向导快速创建springBoot项目、重新导入
springBoot02_案例细节、使用向导快速创建springBoot项目、重新导入
springBoot02_案例细节、使用向导快速创建springBoot项目、重新导入
只要是SpringBootApplication标注的,就是主配置类,比如这个类在com.sjg包下,那么就会在启动项目时,扫描com.sjg包下的所有子包,
将里边的所有组件扫描到spring容器,其实就是spring中的纯注解开发的过程,将原本的配置文件都换成了配置类。
springBoot02_案例细节、使用向导快速创建springBoot项目、重新导入
Selector组件选择器,会把这个场景所需要的所有组件以全限定类名返回,并添加到spring容器中,
添加的就是这些自动配置类,就是当前场景所需要的所有自动配置类
springBoot02_案例细节、使用向导快速创建springBoot项目、重新导入
springBoot02_案例细节、使用向导快速创建springBoot项目、重新导入
springBoot02_案例细节、使用向导快速创建springBoot项目、重新导入
springBoot02_案例细节、使用向导快速创建springBoot项目、重新导入
这里边有对JAVAEE的整体整合解决方案和自动配置
比如说其中我们熟悉的webmvc,看看这里边的自动配置类到底配置了什么
springBoot02_案例细节、使用向导快速创建springBoot项目、重新导入
自动配置类中就有我们熟悉的spring配置文件中,视图解析器,加了Bean注解,将视图解析器交给了spring容器

原来我们spring在配置文件中做的工作,自动配置类都帮我们做了!

使用向导快速创建springBoot项目

新建项目
选择spring initializr
springBoot02_案例细节、使用向导快速创建springBoot项目、重新导入
springBoot02_案例细节、使用向导快速创建springBoot项目、重新导入
选择导入依赖
springBoot02_案例细节、使用向导快速创建springBoot项目、重新导入
springBoot02_案例细节、使用向导快速创建springBoot项目、重新导入
接下来就是联网创建springBoot项目
删除没用的内容
springBoot02_案例细节、使用向导快速创建springBoot项目、重新导入

如果依赖没有导入完整,可以在右侧选择重新导入

springBoot02_案例细节、使用向导快速创建springBoot项目、重新导入
springBoot02_案例细节、使用向导快速创建springBoot项目、重新导入
ResponseBody注解可以标注到类上,这样意思就是类中所有方法返回的数据都加到响应体中给浏览器返回,
还可以使用RestController注解,它是两个注解的合体,更加方便

springBoot02_案例细节、使用向导快速创建springBoot项目、重新导入
访问成功
springBoot02_案例细节、使用向导快速创建springBoot项目、重新导入
springBoot02_案例细节、使用向导快速创建springBoot项目、重新导入
application.properties配置文件可以修改默认设置,比如修改服务器端口号
springBoot02_案例细节、使用向导快速创建springBoot项目、重新导入