firstDemo

1 环境:
(1)jdk 1.7以上
(2)maven 3.2以上
2 maven依赖
为了方便依赖,在这里我创建了一个父类的项目作为根项目,所有的DEMO项目继承根项目。
父项目 maven:


    
        springboot
        com.xubin
        1.0-SNAPSHOT
    
    4.0.0

    first
    jar

    xubin
    http://maven.apache.org

    
        UTF-8
    

    
        
            junit
            junit
            3.8.1
            test
        
    

第一个helloworld 子项目maven:


    
        springboot
        com.xubin
        1.0-SNAPSHOT
    
    
    4.0.0
    first
    jar
    xubin
    
    http://maven.apache.org
    
        UTF-8
    
    
    
        
            junit
            junit
            3.8.1
            test
        
    

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 类:

firstDemo_第1张图片
Kobito.whvmDg.png

firstDemo_第2张图片
Kobito.SDzNyq.png

看到红色标记的说明启动成功。
这时:
http://localhost:8080/helloworld/hi
看到:
firstDemo_第3张图片
Kobito.9MOwNy.png

你可能感兴趣的:(firstDemo)