官网文档最为致命
We need to start by creating a Maven pom.xml file. The pom.xml is the recipe that is used to build your project. Open your favorite text editor and add the following:
①要用到SpringBoot的功能,只需要引入父项目boot-starter-parent
- <parent>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-parentartifactId>
- <version>2.7.5version>
- parent>
-
②想要开发web,只需要添加web的场景启动器
想以往我们Spring,SpringMVC要导入一大推的东西,现在我们只需要添加一个依赖,spring-boot-starter-web,我们称之为web的场景启动器,也就是说我们想要开发web场景了,把这个依赖导进来即可
- <dependencies>
- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-webartifactId>
- dependency>
- dependencies>
①编写业务代码之前,需要有一个主程序将它引导SpringBoot的启动
- /**
- * 主程序类
- * @SpringBootApplication:这是一个SpringBoot应用
- */
- @SpringBootApplication
- public class MainApplication {
- public static void main(String[] args) {
- SpringApplication.run(MainApplication.class,args);
- }
- }
②编写我们的业务代码
- //@ResponseBody
- //@Controller
- @RestController
- public class HelloController {
- @RequestMapping("/hello")
- public String handle01() {
- return "Hello,Spring Boot 2!";
- }
- }
③测试
直接运行main方法即可
成功在页面中显示

④简化配置
application.properties,所有的配置都可以写在这个里面
我们以前想要改tomcat端口号,还要改打开tomcat配置文件等等一大堆,现在SpringBoot是来整合其他所有东西的一个总框架,所以SpringBoot为了简化期间,将我们未来所有的配置都可以抽取在一个配置文件里面,application.properties。可以修改tomcat,SpringMVC的一些设置,什么都可以改噢
server.port=8888
⑤简化部署
我们再也不需要在目标服务器来安装tomcat等一大堆,只需要给我们工程里面引入
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-maven-pluginartifactId>
- plugin>
- plugins>
- build>
把项目打成jar包,直接在目标服务器执行即可。
注意点: