firstDemo

作者: torres9gogogo | 来源:发表于2016-08-22 16:14 被阅读21次

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.pngKobito.whvmDg.png
Kobito.SDzNyq.pngKobito.SDzNyq.png
看到红色标记的说明启动成功。
这时:
http://localhost:8080/helloworld/hi
看到:
Kobito.9MOwNy.pngKobito.9MOwNy.png

相关文章

  • firstDemo

    1 环境:(1)jdk 1.7以上(2)maven 3.2以上2 maven依赖为了方便依赖,在这里我创建了一个父...

  • 面向对象firstdemo

    ButtonApp 封装 两个标签,两个按钮 标签image.pngimage.png 按钮image.png 布...

  • 错误: 找不到或无法加载主类 FirstDemo.class

    问题:在class文件所在路径下用命令行运行该class文件,发生错误: 找不到或无法加载主类 Demo.clas...

网友评论

      本文标题:firstDemo

      本文链接:https://www.haomeiwen.com/subject/nncgsttx.html