【从零开始的Springboot学习(一)】入门demo

打开官网https://spring.io/
在这里插入图片描述

Spring Boot makes it easy to create stand-alone, production-grade
Spring based Applications that you can “just run”.

使用springboot搭建应用只需要打成jar包,然后执行 java -jar xxxx.jar命令

We take an opinionated view of the Spring platform and third-party
libraries so you can get started with minimum fuss. Most Spring Boot
applications need minimal Spring configuration.

大多数 Spring Boot 应用程序需要最少的 Spring 配置。

Features

  • Create stand-alone Spring applications——独立的 Spring 应用程序
  • Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)——内置servlet容器,不需要部署war包
  • Provide opinionated ‘starter’ dependencies to simplify your build configuration——提供固定化起动器依赖,简化配置
  • Automatically configure Spring and 3rd party libraries whenever possible——尽可能自动配置Spring库和第三方库
  • Provide production-ready features such as metrics, health checks, and externalized configuration——提供生产水平功能:健康监测、监控等
  • Absolutely no code generation and no requirement for XML configuration——无需代码生成以及XML配置

为什么学习Springboot?

内置tomcat,提供自动配置,搭建spring应用的脚手架,
解决了:

  • 复杂的配置——配置xml
  • 混乱的依赖管理——导jar包

在这里插入图片描述
打开参考文档去阅读学习

在这里插入图片描述
在这里插入图片描述

创建maven项目,添加pom依赖

在这里插入图片描述
这里需要注意 版本问题
maven版本、jdk版本是当前支持的版本
这里以maven3.8.2,jdk1.8为例

完整pom代码

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.ywq</groupId>
    <artifactId>relspringboot</artifactId>
    <version>1.0-SNAPSHOT</version>

<!--  所有springboot应用都要以该工程为父工程  -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.7.RELEASE</version>
    </parent>

    <dependencies>
<!--  启动器:每一个启动器背后都是一堆的依赖    web启动器 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
</project>

创建controller文件
在这里插入图片描述

@RequestMapping("hello")
@RestController//@Controller+@ResponseBody 返回的是json的数据
@EnableAutoConfiguration//自动配置
public class HelloController {

    @GetMapping("show")
    public String test(){
        return "hello springboot";
    }


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

运行main方法

在这里插入图片描述
可以看到默认端口是8080,在浏览器打开如下:
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值