springboot 入門-Idea創建helloworld工程(1)

一:準備環境

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  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章