zoukankan      html  css  js  c++  java
  • springboot-01 helloworld

    第一个springboot程序

    新建maven项目,添加如下依赖:

    <?xml version="1.0" encoding="UTF-8"?>
    <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">
        <modelVersion>4.0.0</modelVersion>
        <!--项目信息-->
        <groupId>com.mlxs.springboot.helloworld</groupId>
        <artifactId>mlxs-springboot-helloworld</artifactId>
        <version>1.0-SNAPSHOT</version>
    
        <!--父依赖包-->
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.3.2.RELEASE</version>
            <relativePath/>
        </parent>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <java.version>1.8</java.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
    
        </dependencies>
    </project>

    新建项目启动类:

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    /**
     * MainApp类描述:
     *
     * @author yangzhenlong
     * @since 2017/2/9
     */
    @SpringBootApplication
    public class MainApp {
        public static void main(String[] args) {
            SpringApplication.run(MainApp.class, args);
        }
    }

    新建restful接口类:

    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    /**
     * HelloWorldController类描述:
     *
     * @author yangzhenlong
     * @since 2017/2/9
     */
    @RestController
    public class HelloWorldController {
    
        @RequestMapping("/index")
        public String index() {
            return "Hello World";
        }
    }

    然后启动MainApp,浏览器中访问:http://localhost:8080/index,得到响应:

    第一个springboot HelloWorld程序就完成了。

    逃避不一定躲得过,面对不一定最难过
  • 相关阅读:
    数据库连接池
    Apache- DBUtils框架学习
    权限表的设计
    Java的I/O对文件的操作
    Java下载文件
    Java连接MySQL数据库
    C#用log4net记录日志
    C#多线程和线程池
    C#利用反射动态调用DLL并返回结果,和获取程序集的信息
    CephRGW 在多个RGW负载均衡场景下,RGW 大文件并发分片上传功能验证
  • 原文地址:https://www.cnblogs.com/yangzhenlong/p/6382679.html
Copyright © 2011-2022 走看看