SpringBoot學習1:創建第一個SpringBoot項目
阿新 • • 發佈:2019-02-04
進行 ren color 數據 pid 引導 web redis ima
一、新建項目
二、打開項目的pom文件,在裏面添加maven依賴
1 <!--springboot項目依賴的父項目--> 2 <parent> 3 <groupId>org.springframework.boot</groupId> 4 <artifactId>spring-boot-starter-parent</artifactId> 5 <version>2.0.0.RELEASE</version> 6 </parent> 78 <!--註入springboot啟動器--> 9 <dependencies> 10 <dependency> 11 <groupId>org.springframework.boot</groupId> 12 <artifactId>spring-boot-starter-web</artifactId> 13 </dependency> 14 </dependencies>
所謂的 springBoot 啟動器其實就是一些 jar 包的集合。SprigBoot 一共提供 44 啟動器。
例如:
4.1 spring-boot-starter-web
支持全棧式的 web 開發,包括了 romcat 和 springMVC 等 jar
4.2 spring-boot-starter-jdbc
支持 spring 以 jdbc 方式操作數據庫的 jar 包的集合
4.3 spring-boot-starter-redis
支持 redis 鍵值存儲的數據庫操作
三、新建springboot的啟動類Application
1 package com.cccuu; 2 3 import org.springframework.boot.SpringApplication; 4 importorg.springframework.boot.autoconfigure.SpringBootApplication; 5 6 /******************************************* 7 * springboot的引導類 8 * @Package com.cccuu 9 * @Author duan 10 * @Date 2019/1/4 19:18 11 * @Version V1.0 12 *******************************************/ 13 @SpringBootApplication //表示當前類是springboot的啟動類 14 public class Application { 15 16 public static void main(String[] args){ 17 SpringApplication.run(Application.class,args); 18 } 19 }
四:新建一個controller
1 package com.cccuu.controller; 2 3 import org.springframework.web.bind.annotation.RequestMapping; 4 import org.springframework.web.bind.annotation.RestController; 5 6 /******************************************* 7 * 8 * @Package com.cccuu.controller 9 * @Author duan 10 * @Date 2019/1/4 19:34 11 * @Version V1.0 12 *******************************************/ 13 @RestController 14 @RequestMapping("/springboot") 15 public class HelloWorldController { 16 17 @RequestMapping("/hello") 18 public String sayHello(){ 19 return "hello world"; 20 } 21 }
五:運行啟動類Application的main方法
在瀏覽器上進行訪問
註意:
1:啟動類Application掃描包時掃描其所在的包以及該包下的所有子包
SpringBoot學習1:創建第一個SpringBoot項目