-> 從Hello World 開始
1、新建一個Maven項目
2、在pom.xml導入依賴
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
</parent>
<dependencies>
<!--Spring boot的核心包-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!--Spring boot整合web開發的jar-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
3、 編寫一個HelloController
附上代碼:
package cn.ok;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@SpringBootApplication
@Controller
public class HelloController {
@RequestMapping("/hello")
@ResponseBody
public String hello(){
return "Hello! Boot!!";
}
public static void main(String[] args) {
SpringApplication.run(HelloController.class, args);
}
}
4、啓動(main方法)
這樣,一個SpringBoot的項目就啓動起來了;
這時,可以在控制檯上看到 8080 的端口信息(因爲springboot內置了tomcat)。
5、訪問 http://localhost:8080/hello
完成......SpringBoot就是這麼方便快捷!!!