快速入门Spring boot的三步学习

开始前准备工作
1.需要集成开发人员环境
例如: IntelliJ IDEA、Spring Tools、Visual Studio Code、Eclipse等
2.需要jdk 8 或者jdk 11
3.需要下载并配置maven依赖

第一步
使用软件为IntelliJ IDEA
1.新建工程
在这里插入图片描述
选择web依赖
在这里插入图片描述
在这里插入图片描述

第二步
新工程目录结构
在这里插入图片描述
1、设置maven
在这里插入图片描述
注意:
蓝色的,选择自己的maven目录
绿色的,是自己加载的maven本地仓库
红色的,不要改。

2、然后,关闭IDEA,再重新打开

3、下载完maven依赖后
在这里插入图片描述

4、编写控制类HelloController
在这里插入图片描述
在这里插入图片描述

第三步

运行DemoApplication
在这里插入图片描述

运行后会得到控制台以下信息
在这里插入图片描述
打开浏览器,输入http://localhost:8080/
在这里插入图片描述

Spring boot成功启动
Spring boot快速入门官网,https://spring.io/quickstart
官网译文:
Spring Quickstart Guide
What you’ll build
You will build a classic “Hello World!” endpoint which any browser can connect to. You can even tell it your name, and it will respond in a more friendly way.
翻译:
你会建立什么
您将构建一个经典的“ Hello World!”。任何浏览器都可以连接到的端点。您甚至可以告诉它您的名字,它将以更友好的方式响应。

What you’ll need
An Integrated Developer Environment (IDE)
Popular choices include IntelliJ IDEA**, Spring Tools, Visual Studio Code, or Eclipse, and many more.
A Java™ Development Kit (JDK)
We recommend AdoptOpenJDK version 8 or version 11.
翻译:
你需要什么
集成开发环境(IDE)
受欢迎的选择包括再观, 弹簧工具, VisualStudio代码,或月食还有更多。
JAVA™开发工具包(JDK)
我们建议AdoptOpenJDK第8版或第11版。

Step 1: Start a new Spring Boot project
步骤1:开始一个新的Spring Boot项目
Use start.spring.io to create a “web” project. In the “Dependencies” dialog search for and add the “web” dependency as shown in the screenshot. Hit the “Generate” button, download the zip, and unpack it into a folder on your computer.
翻译:
使用Start.spring.io若要创建“web”项目,请执行以下操作。在“依赖项”对话框中搜索并添加“web”依赖项,如屏幕快照所示。点击“Generate”按钮,下载zip,然后将其解压到计算机上的一个文件夹中。
在这里插入图片描述
Projects created by start.spring.io contain Spring Boot, a framework that makes Spring ready to work inside your app, but without much code or configuration required. Spring Boot is the quickest and most popular way to start Spring projects.
翻译:
创建的项目Start.spring.io含弹簧靴一个框架,使Spring可以在应用程序中工作,但不需要太多的代码或配置。SpringBoot是启动Spring项目最快也是最受欢迎的方式。

Step 2: Add your code
步骤2:添加您的代码
Open up the project in your IDE and locate the DemoApplication.java file in the src/main/java/com/example/demo folder. Now change the contents of the file by adding the extra method and annotations shown in the code below. You can copy and paste the code or just type it.
翻译:
在IDE中打开项目并找到DemoApplication.java文件中的src/main/java/com/example/demo文件夹。现在,通过添加下面代码中显示的额外方法和注释来更改文件的内容。您可以复制和粘贴代码,或者只需键入它。
在这里插入图片描述
The hello() method we’ve added is designed to take a String parameter called name, and then combine this parameter with the word “Hello” in the code. This means that if you set your name to “Amy” in the request, the response would be “Hello Amy”.

The @RestController annotation tells Spring that this code describes an endpoint that should be made available over the web. The @GetMapping(“/hello”) tells Spring to use our hello() method to answer requests that get sent to the http://localhost:8080/hello address. Finally, the @RequestParam is telling Spring to expect a name value in the request, but if it’s not there, it will use the word “World” by default.
翻译:
这个hello()方法被设计为接受一个名为name,然后将此参数与Word组合。"Hello"在密码里。这意味着如果你把你的名字“Amy”在请求中,答复将是“Hello Amy”.

这个@RestController注释告诉Spring,这段代码描述了应该通过Web提供的端点。这个@GetMapping(“/hello”)告诉Spring使用我们的hello()方法来响应发送到http://localhost:8080/hello地址。最后,@RequestParam告诉Springname值,但如果不存在,则默认使用“World”一词。

Step 3: Try it
步骤3:尝试
Let’s build and run the program. Open a command line (or terminal) and navigate to the folder where you have the project files. We can build and run the application by issuing the following command:
翻译:
让我们构建并运行这个程序。打开命令行(或终端),导航到项目文件所在的文件夹。我们可以通过发出以下命令来构建和运行应用程序:
MacOS/Linux:
在这里插入图片描述
Windows:
在这里插入图片描述
You should see some output that looks very similar to this:
您应该会看到一些非常类似于此的输出:
在这里插入图片描述

The last couple of lines here tell us that Spring has started. Spring Boot’s embedded Apache Tomcat server is acting as a webserver and is listening for requests on localhost port 8080. Open your browser and in the address bar at the top enter http://localhost:8080/hello. You should get a nice friendly response like this:
最后几句话告诉我们春天已经开始了。Spring Boot的嵌入式ApacheTomcat服务器充当Web服务器,并侦听localhost港8080。打开您的浏览器,并在地址栏的顶部回车。Http://localhost:8080/hello。你应该得到这样的友好回应:
在这里插入图片描述
完——————成

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值