springboot官方文档解析--HelloWorld

Springboot简介

特征:

1.创建独立德Spring应用程序

2.直接嵌入Tomcat,Jetty或Undertow(无需部署WAR文件)

3提供自以为是“入门”依赖项,以简化您德构建配置

4尽可能德自动配置Spring和使用3rdPary库(第三方库)

5提供可用于生产德功能,例如指标,运行状况检查和外部化配置

6完全没有代码生成,也不需要xml配置

Spring快速入门指南

1.你会建立什么?

您将构建一个经典的“HELLO World !”。任何浏览器都可以连接到的端点,甚至你可以告诉它你的名字,它将以更友好的方式响应

2.你需要的开发环境?

集成开发人员环境(IDE工具)

热门工具包括Intellij Idea ,SpringTools,Visual Studio Code 或者 Eclipse 等

3jdk版本(jdk8或者jdk11)

推荐AdoptOpenJDK version 8 or version 11。

 

步骤1:创建一个新的Spring Boot项目

这里可以推荐的工具,springboot是一个框架,可让spring项目运行在应用程序中,而无需太多代码配置。Springboot是启动Spring项目最快,最受欢迎的方式。

步骤2:添加您的代码:

在IDE中打开项目,然后在DemoApplication.java文件src/main/java/com/example/demo夹中找到文件。现在,通过添加以下代码中所示的额外方法和注释来更改文件的内容。您可以复制并粘贴代码,也可以只键入它。


              package com.example.demo;
              import org.springframework.boot.SpringApplication;
              import org.springframework.boot.autoconfigure.SpringBootApplication;
              import org.springframework.web.bind.annotation.GetMapping;
              import org.springframework.web.bind.annotation.RequestParam;
              import org.springframework.web.bind.annotation.RestController;
              
              @SpringBootApplication
              @RestController
              public class DemoApplication {
                
                  
                  public static void main(String[] args) {
                  SpringApplication.run(DemoApplication.class, args);
                  }
                  
                  @GetMapping("/hello")
                  public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
                  return String.format("Hello %s!", name);
                  }
                
              }
 

          hello()方法中我们增加一个参数名称位name的字符串参数,然后将这个参数和代码中单词“hello”组合。如何您在请求中将name参数设置成Amy,则响应返回“HELLO Amy”.

   @RestController注解是通知Spring,这段代码可以在彰显在网站上,

   @GetMapping("/hello")是通知Spring使用我们的hello方法来回答这个请求,被发送到请求http://localhost:8080/hello

最后@RequestMapping告诉Spring期望name请求中的值,但是如果不存在,默认情况下,它将使用单词“World”

步骤3:运行

MacOS / Linux:

 

./mvnw spring-boot:run

windows:

./mvnw spring-boot:run

当我们的Spring Boot应用程序启动时,终端会输出各种日志语句。

日志输出:最后2行告诉我们Spring已经开始。Spring Boot的嵌入式ApacheTomcat 服务器充当Web服务器,并在localhost port上监听8080请求。http:// localhost:8080/hello

 

 

案例详细截图如何---(工具 intellj)

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值