程序员英语之Spring篇

news/2024/9/24 4:19:48/

springioquickstart_0">spring.io/quickstart

本期课程讲解Spring官网的快速上手页面

官网地址 https://spring.io/quickstart

Spring Quickstart Guide

在这里插入图片描述

Spring 快速开始指南

Guide

指南

What you’ll build

接下来你将要构建的是什么?

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!”任何浏览器都可以连接的端点。你甚至可以告诉它你的名字,它会以一种更友好的方式回应你。

You will build a classic “Hello World!” endpoint which any browser can connect to

你将要构建的是一个经典的 helloworld端点,任何浏览器都可以连接上。

classic 经典的

endpoint 端点,终端

browser 浏览器

connect 连接

You can even tell it your name, and it will respond in a more friendly way.

你甚至可以告诉它你的名字,它会以一种更友好的方式回应你。

respond 应答

What you’ll need

你需要什么

An Integrated Developer Environment (IDE)

一个集成开发环境

Integrated 集成

Developer 开发

Environment 环境

Popular choices include IntelliJ IDEA, Spring Tools, Visual Studio Code, or Eclipse, and many more.

比较流行的选择包括 IntelliJ IDEA, Spring Tools, Visual Studio Code, 或者Eclipse,等等。

include 包含,包括

A Java™ Development Kit (JDK)

对jdk的要求

We recommend AdoptOpenJDK version 8 or version 11.

我们推荐使用 AdoptOpenJDK 8 或者 11版。

recommend 建议,推荐

Step 1: Start a new Spring Boot project

第一步,创建一个新的springboot项目

Step 步骤

project 项目

Use spring.io/" rel="nofollow">start.spring.io to create a “web” project.

使用start.spring.io这个网站创建一个web项目

create 创建

In the “Dependencies” section search for and add the “web” dependency as shown in the screenshot.

在“依赖项”部分,搜索并添加“web”依赖,如屏幕截图所示。

Dependencies 依赖

section 一部分

search搜索

shown in … 如xx所示

screenshot 屏幕截图

在这里插入图片描述

Hit the green “Generate” button, download the zip, and unpack it into a folder on your computer.

点击绿色的生成按钮,下载zip文件,并将其解压缩到你电脑上上的一个文件夹里。

Hit 点击

Generate生成

button 按钮

download 下载

zip 压缩格式

unpack 解开,解压缩

folder 文件夹

Step 2: Add your code

第二步,添加你的代码

java_file_in_the_srcmainjavacomexampledemofolder_129">Open up the project in your IDE and locate the DemoApplication.java file in the src/main/java/com/example/demofolder.

用ide打开刚下载的项目,并在src/main/java/com/example/demo文件夹中找到DemoApplication.java文件

locate 定位,位于

Now change the contents of the file by adding the extra method and annotations shown in the code below.

现在,修改文件内容,添加一些额外的方法和注解,如下代码所示

change 改变,修改

contents 内容

file 文件

extra 额外,扩展

method 方法

annotations 注解(不是注释)

java">              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@RestControllerpublic 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);}}
You can copy and paste the code or just type it.

你可以直接复制粘贴代码,或者自己敲。

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.

hello()这个方法是我们添加的,我们把它设计成了一个可以接受String类型参数的方法,这个参数名是name,在方法体里,连接了"Hello"这个词。

designed 设计的

take a String parameter 获取到一个String类型的参数

combine 连接,联合

This means that if you set your name to “Amy” in the request, the response would be “Hello Amy”.

这么写的意思是,如果在请求发过来的时候name这个参数被设置成了amy,那么响应的结果就是“Hello Amy”

request 请求

response 响应

The @RestController annotation tells Spring that this code describes an endpoint that should be made available over the web.

@RestController这个注解告诉Spring,我们的这些代码想要开启一个可用的web服务端点

describes 描述

The @GetMapping(“/hello”) tells Spring to use our hello() method to answer requests that get sent to the http://localhost:8080/hello address.

@GetMapping(“/hello”) 这个注解写在了hello()这个方法上,告诉Spring我们想用这个方法应答请求,当请求地址为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.

最后,@RequestParam 告诉Spring在处理请求时,期望接收到一个传递过来的'name'值,但是如果没有传值过来那么就使用' World '这个词作为默认值。

expect 期望

default 默认


http://www.ppmy.cn/news/1433918.html

相关文章

C#中的 task 和 task<T> 之间的区别

C#中的Task和Task是用来处理异步编程的关键类,它们之间的主要区别在于结果的返回类型。在这篇博客文章中,我们将详细解析这两个类的差异,并提供一些示例来说明它们在实际编程中的应用。 1、使用与功能区别 1.1Task Task类是C#异步编程的基…

《ElementPlus 与 ElementUI 差异集合》el-select 差异点,如:高、宽、body插入等

宽度 Element UI 父元素不限制宽度时,默认有个宽度 207px; 父元素有固定宽度时,以父元素宽度为准; Element Plus 父元素不限制宽度时,默认100%; 父元素有固定宽度时,以父元素宽度为准&#x…

如何更好的管理个人财务?使用极空间部署私有记账系统Firefly III

如何更好的管理个人财务?使用极空间部署私有记账系统Firefly III 哈喽小伙伴们好,我是Stark-C~ 不知道屏幕前的各位“富哥”日常生活中是怎么管理自己巨额财富的,反正对于像我这样年薪过千的摸鱼族来说,请一个专业的理财顾问多多…

Go语言 Map

基本介绍 Map 是一种无序的键值对的集合。 基本使用 初始化 初始化 Map 可以使用 make 函数,也可以使用字面量的方式直接初始化值。 // 创建一个空的 Mapm1 : make(map[string]int)// 使用字面量的方式m2 : map[string]int{"apple": 1,"banana&q…

AIGC时代下,知识管理有点多余了?

尤瓦尔在《今日简史》中曾断言“每过10年,你都要接受再培训,你学过的知识都可能被颠覆。”。而在当今AIGC爆火,AI技能日新月异的情况下,我们所接触、了解到的信息、知识也在不断增多和迭代。这种情况下,作为普通人&…

SpringBoot 3.2.5 引入Swagger(OpenApi)

SpringBoot 3.2.5 引入Swagger(OpenApi) pom文件配置文件启动类Controller 层ApiFox题外话 springdoc-openapi 和 swagger 都可以用,用其中一个就行,不用两个都引入。 这里简单记录以下springdoc-openapi。 springdoc-openapi(J…

2024创业项目新方向,智享无人实景直播配合智能贴图数字人,让直播更简单,帮助商家快速引流客户到店,帮助创业者轻松实现梦想!

随着科技的迅猛发展,直播行业也经历了一次又一次的变革和创新。在2024年,AI实景无人直播成为了这个领域的全新宠儿,为商家和观众带来了前所未有的智能、高效体验。这种革命性的直播方式不仅降低了运营成本,还极大地提升了直播的效…

算法学习系列(五十一):背包模型(一)

目录 引言一、采药二、装箱问题三、宠物小精灵之收服 引言 关于 背包问题 可以参考我之前的博客,由于基础的算法和模板已经学过了,所以现在就是开始学模型了,难点就是阅读理解、抽象模型、代码熟练度、心理素质也就是这几个难点了&#xff0…