springboot的从零探索1-从一个hello-world开始

前言

本身不是后端人,但是在公司项目上用的是springboot的框架,而且感觉还可以,所以经常会在网上百度一些springboot的问题,发现大多是解决不了根本;所以需要系统性的学习,而系统性的学习,又很多是视频,得不到要点,所以这里我就讲官方的example走一边,算是翻译,也算是为以后的初学者们做一点贡献;主要参考流程是官网的demo以及入门指南
https://spring.io/guides#getting-started-guides

构建restful web服务

其实很简单,我希望通过springboot搭建一个服务,能够调用他的接口,返回给我的参数即可;
需要:
1 jdk 1.8
2 IDEA
3 maven
这些东西自己搭建

步骤

1 利用spring官网的初始化插件构建一个初始的springboot框架
参考地址:https://start.spring.io/
maven创建的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 https://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.3.2.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.example</groupId>
	<artifactId>rest-service</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>rest-service</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>
			<exclusions>
				<exclusion>
					<groupId>org.junit.vintage</groupId>
					<artifactId>junit-vintage-engine</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
	</dependencies>

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

</project>

2 创建对应的请求
在这里插入图片描述
这里是我创建好的,具体的demo,见我的博文:
https://blog.csdn.net/wangbiao9292/article/details/110947040
这里的重点,主要是说明一些注解的作用跟着官网指南:
(1) @RequestMapping确保将HTTP GET请求/test映射到该test()方法。说白了,在你前端发出请求时:http://127.0.0.1/tset,这时,为什么能够访问到test()方法,就是@RequestMapping的作用
在这里插入图片描述注意:常见的还有:
1 @GetMapping
2 @PostMapping
3 @RequestMapping(method=GET) 默认为GET

为了方便大家看,这里我截取一张图供大家参考:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

李卓书

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值