1. 程式人生 > >2springboot:快速建立springboot專案

2springboot:快速建立springboot專案

 使用IDEA快速建立springboot專案流程:

 

 建立新的專案選擇

 

 專案的命名以及包名

 

 

 需要什麼包就匯入什麼包

 

 

 進行測試的單元

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>

 

此時的工程預設有這個啟動的主程式

Springboot01Application.java
@SpringBootApplication
public class Springboot01Application {
    public static void main(String[] args) {
        SpringApplication.run(Springboot01Application.class, args);
    }
}

 

 新建一個controller包和controller類:

//此時類的所有方法都會返回資料給瀏覽器(物件是專為json)
//@RestController  = @ResponseBody + @Controller
@ResponseBody @Controller public class Helloword { @RequestMapping("/hello") public String hello(){ return "Hello tow!"; } }

 執行訪問:

 

 

 springboot工程結構:

 

static資料夾:儲存所有的靜態資源 templates資料夾:儲存所有的模板頁面(Springboot預設jar使用嵌入式的Tomcat,預設不支援jsp頁面);可以使用模板引擎 application.properties:springboot應用的配置檔案