SpringBoot——01概念&入门
SpringBoot概念:
是什么?
1.是一些开发好了maven模块,只需要以maven导入对应的springboot模块,就能用很少代码完成一堆功能,它使用maven的方式对Spring应用开发进行进一步封装和简化。
2.Springboot就是为了简化spring应用搭建,开发,部署,监控的开发工具。
干什么?(目的)
简化Spring应用搭建,开发,部署,运维等。
常用的模块
spring-boot-starter-web,Spring-boot-starter-jdbc,Spring-boot-starter-data jpa,
Spring-boot-starter-mybatis,Spring-boot-starter-test
SpringBoot入门:
1.创建单项目建议使用:spring initializr方式创建。
2.创建多模块项目:
①先创建普通的maven项目
父model的pom文件配置版本管理
<dependencyManagement>
<dependencies>
<!--springboot版本管理-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.0.5.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
子模块pom文件导入对应的模块
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--热部署依赖包-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>true</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!--fork : 如果没有该项配置,可能devtools不会起作用,即应用不会restart -->
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
入口类
@SpringBootApplication
public class HelloApplication {
public static void main(String[] args) {
SpringApplication.run(HelloApplication.class);
}
}
测试Controller
@RestController
@RequestMapping("/hello2")
public class HelloController2 {
@RequestMapping("/hi")
public String hello(String name){
return name+"啦啦啦啦";
}
@RequestMapping("/hi2")
public String hello2(String name){
return name+"啦啦啦啦";
}
}
注:@[email protected][email protected] 官方推荐使用