firstDemo

1 環境:
(1)jdk 1.7以上
(2)maven 3.2以上
2 maven依賴
為了方便依賴,在這里我創建了一個父類的項目作為根項目,所有的DEMO項目繼承根項目。
父項目 maven:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>springboot</artifactId>
        <groupId>com.xubin</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>first</artifactId>
    <packaging>jar</packaging>

    <name>xubin</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

第一個helloworld 子項目maven:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>springboot</artifactId>
        <groupId>com.xubin</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    
    <modelVersion>4.0.0</modelVersion>
    <artifactId>first</artifactId>
    <packaging>jar</packaging>
    <name>xubin</name>
    
    <url>http://maven.apache.org</url>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

3 程序
(1)controller:

package com.xubin.controller;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Torres on 16/8/22.
 */
@RestController
@Configuration
@EnableAutoConfiguration
@RequestMapping("/helloworld")
public class HelloWorldDemo {
    @RequestMapping("/hi")
    public String  getHello()
    {
        return "hellowold,hi";
    }
}

(2)啟動類:

   package com.xubin;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * Hello world!
 */
 //@SpringBootApplication  
@SpringBootApplication
public class App {
    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}

(3) 運行:
直接啟動main 類:

Kobito.whvmDg.png
Kobito.whvmDg.png

Kobito.SDzNyq.png
Kobito.SDzNyq.png

看到紅色標記的說明啟動成功。
這時:
http://localhost:8080/helloworld/hi
看到:
Kobito.9MOwNy.png
Kobito.9MOwNy.png

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • Spring Cloud為開發人員提供了快速構建分布式系統中一些常見模式的工具(例如配置管理,服務發現,斷路器,智...
    卡卡羅2017閱讀 134,924評論 18 139
  • Spring Boot 參考指南 介紹 轉載自:https://www.gitbook.com/book/qbgb...
    毛宇鵬閱讀 46,954評論 6 342
  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 173,292評論 25 708
  • 01 注冊簡書其實早已有一段時間,在老姐的強力推薦下,我堅持每天刷簡書! 刷簡書也有好些日子了,看了很多作者寫的文...
    高志龍閱讀 664評論 1 0
  • 《戰國策.燕策》:“趙且伐燕,蘇代為燕謂惠王曰:‘今者臣來過易水,蚌方出曝,而鷸啄其肉,蚌合而箝其喙。鷸曰:‘今日...
    千譽嘉言閱讀 788評論 0 2