spring-tool-suite(STS) 創建 spring boot項目


1.創建一個Spring Starter Project工程(new --> Spring Starter Project)

2.選擇自己需要的依賴,因為想要通過REST方式來驗證是否成功創建,所以勾選了web(會在pom.xml文件中看到該依賴內容);然后點擊next-->Finish即可

3.此時就可以創建完了,下面是程序入口

package com.fengxm;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class FirstspringbootApplication {

    public static void main(String[] args) {
        SpringApplication.run(FirstspringbootApplication.class, args);
    }
}

4.寫一個HelloController類,用於圖形驗證

package com.fengxm;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController 
// 等同於同時加上了@Controller和@ResponseBody
public class HelloController {
    // 訪問/hello或者/hi任何一個地址,都會返回一樣的結果
    @RequestMapping(value = { "/hello", "/hi" }, method = RequestMethod.GET)
    public String say() {
        return "hi you!!!";
    }
}

5.在FirstspringbootApplication.java類上右鍵,Run As -->Spring Boot App,執行(默認端口為8080)

在瀏覽器中輸入連接http://localhost:8080/hello或http://localhost:8080/hi,在頁面顯示如下

 

 

 代碼地址

 

參考:方志鵬的博客


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM