二十九、idea建立Spring boot 專案(MAVEN)
阿新 • • 發佈:2019-01-14
-
開啟idea,點選建立新專案,選擇Spring Initializr
-
點選next,填寫Group和Artifact
-
選擇Web,再選擇Web複選框
-
填寫Project name,點選finish
-
開啟專案目錄,刪除以下資料夾和檔案
-
該類是自動生成的,是程式的入口
package com.example.demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } }
- 建立TestController
package com.example.demo.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/demo") public class TestController { @RequestMapping("/hello") public String test() { return "hello world .."; } }
-
啟動DemoApplication
-
在位址列中輸入http://localhost:8080/demo/hello
啟動之後訪問異常處理:https://www.cnblogs.com/lilinzhiyu/p/7921890.html