1. 程式人生 > >2springboot:快速創建springboot項目

2springboot:快速創建springboot項目

artifact 文件 ebo 單元 ons ota dep end pri

使用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應用的配置文件

2springboot:快速創建springboot項目