1. 程式人生 > >spring boot hello world 搭建

spring boot hello world 搭建

-i ref quest img turn stat oid lease void

1.下載地址:

Eclipse:http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/neonr

Spring Tool Suite:https://spring.io/tools/sts/all

2.使用版本為:

Eclipse:eclipse-jee-neon-R-win32-x86_64.zip

Spring Tool Suite:springsource-tool-suite-3.9.0.RELEASE-e4.6.3-updatesite.zip

2.插件安裝:

  采用離線安裝,安裝方式類似svn的安裝。

3.新建工程:

技術分享

註意,過程中選擇相應的組件,如web,mybatis,redis 等。

4.hello World 代碼的編寫

共兩個類。

類1:

package com.example.first;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;  
import org.springframework.web.bind.annotation.PathVariable;  
import org.springframework.web.bind.annotation.RequestMapping;  
import org.springframework.web.bind.annotation.RestController; @RestController @EnableAutoConfiguration public class Example { @RequestMapping("/") String home() { return "Hello World!"; } @RequestMapping("/hello/{myName}") String index(@PathVariable String myName) {
return "Hello "+myName+"!!!"; } }


類 2:

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

5.啟動方式

右鍵項目名稱,run as application ,選擇上面的Application 類。

瀏覽器輸入 http://localhost:8080/ 即可看到 Hello World!

spring boot hello world 搭建