1.开始一个新的springboot项目
设置相关依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.9.RELEASE</version>
</dependency>
2.创建DemoApplicatin添加注解@SpringBootApplication说明这是一个springboot应用
在主程序类上 添加main方法
跑起程序
SpringApplication.run(DemoApplication.class, args)
3.创建controller
//@Controller
@RestController
public class HelloController {
@RequestMapping("/hello")
public String hello(){
return "hello";
}
}
我们可以看出
@Controller
@ResponseBody
public @interface RestController {
@AliasFor(
annotation = Controller.class
)
String value() default "";
}
@RestController=@Responsebody+@Controller
4.启动应用
5.application.properties为配置列表
优先使用我们自定义配置 然后再使用父项目的配置
6.我们不要自己配置tomcat等等就可以运行这个程序
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
我们可以将应用打包为jar包发布,然后会集成我们的所有环境
7.父项目
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
主要的核心功能就是依赖版本号的管理 已经纳入了很多的依赖
我们也可以自定义版本仲裁
<properties>
<java.version>11</java.version>
<mysql.version>5.1.43</mysql.version>
</properties>
8.starter启动器
引入相应的开发场景 spring-boot - start-*
全套引入我们的开发环境模块场景
核心依赖启动器
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>