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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,188评论 19 139
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 47,171评论 6 342
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,671评论 25 709
  • 01 注册简书其实早已有一段时间,在老姐的强力推荐下,我坚持每天刷简书! 刷简书也有好些日子了,看了很多作者写的文...
    高志龙阅读 3,942评论 1 0
  • 《战国策.燕策》:“赵且伐燕,苏代为燕谓惠王曰:‘今者臣来过易水,蚌方出曝,而鹬啄其肉,蚌合而箝其喙。鹬曰:‘今日...
    千誉嘉言阅读 4,183评论 0 2

友情链接更多精彩内容