springboot 創建第一個簡單的web案例。
使用工具idea;java8;maven-3.5.4
1、使用idea創建一個project ,選擇Spring Initializr ,下一步,下一步,選擇web項,下一步,finish.
2、pom.xml用來配置依賴,打開後能看到有web的相關依賴
<dependencies>
<!--web相關依賴-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--測試類test依賴-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
3、在DemoApplication類的同目錄下創建一個ControllerDemo類如下
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/test")
public class ControllerDemo {
@RequestMapping("/demo01")
public String demo01(){
return "hello world!";
}
}
4、啓動DemoApplication.java 該類在創建工程時自動生成
5、運行程序時查看日誌端口爲8080,使用瀏覽器進行訪問:http://localhost:8080/test/demo01
這樣一個簡單的springbootweb案例就完成了。