1. 程式人生 > >springboot 入門-Idea建立helloworld工程

springboot 入門-Idea建立helloworld工程

一:準備環境

1.JDK環境:JDK1.8

開發環境:IDEA2018.3

二:建立IDEA專案工程

三:HelloWorld例項

  1. 目錄結構:

  2. 編寫controllor程式碼

    package com.controller;
    
    import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    @EnableAutoConfiguration
    public class helloController {
    
        @RequestMapping("/hello")
        private String hello(){
            return "Hello World!";
        }
    }
    
  3. 注意!!!

    DemoApplication 一定要放在包的最外層!!!否則出現以下錯誤!!!
    

四:專案啟動

兩種方式:

  1. application啟動
  2. IDEA工具欄啟動

五:測試helloworld

開啟瀏覽器輸入:   http://localhost:8080/hello