1. 程式人生 > 其它 >【Java】【Spring Boot】CP01:建立一個SpringBoot專案(Spring Initializr)

【Java】【Spring Boot】CP01:建立一個SpringBoot專案(Spring Initializr)

IDEA使用Spring Initializr方式建立一個SpringBoot專案

設定(可跳過這一步)

點選Apply 然後點選OK

建立專案

目前不需要勾選什麼,以後根據需要勾選

建立一個名為controller的資料夾(控制層),並在資料夾中建立一個HelloController.java

@RestController //該註解為組合註解,等同於Spring中@controller+@ResponseBody註解
// 上面註解的作用是將當前類作為控制層新增到Spring容器中,同時該類無法返回jsp頁面,而是返回JSON字串
public class HelloController
{
    @GetMapping("/hello") //該註解等同於Spring中的@requestMapping(RequestMethod,GET)
    // 上面註解的作用是設定方法的訪問路徑並限定其訪問方式為Get
    public String hello(){
        return  "hello Spring Boot";
    }
}

檢查pom.xml檔案

檢查pom.xml

在瀏覽器中輸入 localhost:8080/hello

作者:萌狼藍天,轉載請註明原文連結:https://www.cnblogs.com/mllt/p/springboot20220301.html | 萌狼藍天@嗶哩嗶哩 | QQ:3447902411(僅限技術交流,新增請說明方向)| 歡迎關注我的嗶哩嗶哩