SpringBoot概念:java
是什麼?web
1.是一些開發好了maven模塊,只須要以maven導入對應的springboot模塊,就能用不多代碼完成一堆功能,它使用maven的方式對Spring應用開發進行進一步封裝和簡化。spring
2.Springboot就是爲了簡化spring應用搭建,開發,部署,監控的開發工具。springboot
幹什麼?(目的)mybatis
簡化Spring應用搭建,開發,部署,運維等。app
經常使用的模塊
spring-boot-starter-web,Spring-boot-starter-jdbc,Spring-boot-starter-data jpa,運維
Spring-boot-starter-mybatis,Spring-boot-starter-testmaven
SpringBoot入門:spring-boot
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+"啦啦啦啦"; } }
注:@RestController=@Controller+@ResponseBody 官方推薦使用