自动创建Spring Boot 工程,太爽了!

Spring Boot 大家都知道是啥吧?

顺便再往下看,今天博主给你带来年轻人的第一个 Spring Boot 工程,撸码史无前例的轻松,那就一个字:爽!

第一步

打开这个网站,快速生成一个 Spring Boot 项目。

https://start.spring.io/

废话不说,看下图,几秒搞定!

第二步

解压生成的 demo 项目,导入到 IDE 中。

来看下 pom.xml 文件内容:

<?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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>cn.javastack</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

以及 DemoApplication 入口类内容:

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

这里不作过多介绍。

第三步

添加年轻人的第一个 Spring Boot 请求:/hello.

修改 DemoApplication 添加一个请求方法,修改后的代码内容如下:

@RestController
@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @GetMapping("/hello")
    public String hello() {
        return "hello";
    }

}

第四步

运行 Spring Boot 应用,在 IDE 中运行 DemoApplication main 方法即可。

如图所示,程序已经启动,牛逼啊,2秒多就启动起来了,爽。。。它能跑起来,是因为内置了 Tomcat 容器,当然你也可以替换或者自定义配置,

第五步

访问 /hello 请求,在浏览器中访问以下链接:

http://localhost:8080/hello

如下图所示,页面输出了hello.

总结

我就在官网生成一个 demo 项目,然后导入到 IDE 中,写几行代码后输出:hello,开启了年轻人的第一个 Spring Boot 项目。

全程下来,我就只用几分钟,然后只加了 5 行代码,没有其他乱七八糟的 XML 配置,这叫一个爽。


   转载请注明


《自动创建Spring Boot 工程,太爽了!》 by chen guoji under cc_by_name licensed
 上一篇
这么牛逼的正则表达式,可惜你不会写! 这么牛逼的正则表达式,可惜你不会写!
一、校验数字的表达式数字: ^[0-9]*$ n位的数字: ^\d{n}$ 至少n位的数字: ^\d{n,}$ m-n位的数字: ^\d{m,n}$ 零和非零开头的数字: ^(0|[1-9][0-9]*)$ 非
2019-06-28
下一篇 
【美团】Java岗154道面试题 【美团】Java岗154道面试题
Java集合22题ArrayList 和 Vector 的区别。说说 ArrayList,Vector, LinkedList 的存储性能和特性。快速失败 (fail-fast) 和安全失败 (fail-safe) 的区别是什么?hashm
2019-06-21
  目录